00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "avformat.h"
00023 #include "rawdec.h"
00024 #include "pcm.h"
00025 #include "libavutil/log.h"
00026 #include "libavutil/opt.h"
00027 #include "libavutil/avassert.h"
00028
00029 #define RAW_SAMPLES 1024
00030
00031 static int raw_read_packet(AVFormatContext *s, AVPacket *pkt)
00032 {
00033 int ret, size, bps;
00034
00035
00036 size= RAW_SAMPLES*s->streams[0]->codec->block_align;
00037
00038 ret= av_get_packet(s->pb, pkt, size);
00039
00040 pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
00041 pkt->stream_index = 0;
00042 if (ret < 0)
00043 return ret;
00044
00045 bps= av_get_bits_per_sample(s->streams[0]->codec->codec_id);
00046 av_assert1(bps);
00047 pkt->dts=
00048 pkt->pts= pkt->pos*8 / (bps * s->streams[0]->codec->channels);
00049
00050 return ret;
00051 }
00052
00053 static const AVOption pcm_options[] = {
00054 { "sample_rate", "", offsetof(RawAudioDemuxerContext, sample_rate), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
00055 { "channels", "", offsetof(RawAudioDemuxerContext, channels), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
00056 { NULL },
00057 };
00058
00059 #define PCMDEF(name_, long_name_, ext, codec) \
00060 static const AVClass name_ ## _demuxer_class = { \
00061 .class_name = #name_ " demuxer", \
00062 .item_name = av_default_item_name, \
00063 .option = pcm_options, \
00064 .version = LIBAVUTIL_VERSION_INT, \
00065 }; \
00066 AVInputFormat ff_pcm_ ## name_ ## _demuxer = { \
00067 .name = #name_, \
00068 .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
00069 .priv_data_size = sizeof(RawAudioDemuxerContext), \
00070 .read_header = ff_raw_read_header, \
00071 .read_packet = raw_read_packet, \
00072 .read_seek = ff_pcm_read_seek, \
00073 .flags = AVFMT_GENERIC_INDEX, \
00074 .extensions = ext, \
00075 .raw_codec_id = codec, \
00076 .priv_class = &name_ ## _demuxer_class, \
00077 };
00078
00079 PCMDEF(f64be, "PCM 64-bit floating-point big-endian",
00080 NULL, AV_CODEC_ID_PCM_F64BE)
00081
00082 PCMDEF(f64le, "PCM 64-bit floating-point little-endian",
00083 NULL, AV_CODEC_ID_PCM_F64LE)
00084
00085 PCMDEF(f32be, "PCM 32-bit floating-point big-endian",
00086 NULL, AV_CODEC_ID_PCM_F32BE)
00087
00088 PCMDEF(f32le, "PCM 32-bit floating-point little-endian",
00089 NULL, AV_CODEC_ID_PCM_F32LE)
00090
00091 PCMDEF(s32be, "PCM signed 32-bit big-endian",
00092 NULL, AV_CODEC_ID_PCM_S32BE)
00093
00094 PCMDEF(s32le, "PCM signed 32-bit little-endian",
00095 NULL, AV_CODEC_ID_PCM_S32LE)
00096
00097 PCMDEF(s24be, "PCM signed 24-bit big-endian",
00098 NULL, AV_CODEC_ID_PCM_S24BE)
00099
00100 PCMDEF(s24le, "PCM signed 24-bit little-endian",
00101 NULL, AV_CODEC_ID_PCM_S24LE)
00102
00103 PCMDEF(s16be, "PCM signed 16-bit big-endian",
00104 AV_NE("sw", NULL), AV_CODEC_ID_PCM_S16BE)
00105
00106 PCMDEF(s16le, "PCM signed 16-bit little-endian",
00107 AV_NE(NULL, "sw"), AV_CODEC_ID_PCM_S16LE)
00108
00109 PCMDEF(s8, "PCM signed 8-bit",
00110 "sb", AV_CODEC_ID_PCM_S8)
00111
00112 PCMDEF(u32be, "PCM unsigned 32-bit big-endian",
00113 NULL, AV_CODEC_ID_PCM_U32BE)
00114
00115 PCMDEF(u32le, "PCM unsigned 32-bit little-endian",
00116 NULL, AV_CODEC_ID_PCM_U32LE)
00117
00118 PCMDEF(u24be, "PCM unsigned 24-bit big-endian",
00119 NULL, AV_CODEC_ID_PCM_U24BE)
00120
00121 PCMDEF(u24le, "PCM unsigned 24-bit little-endian",
00122 NULL, AV_CODEC_ID_PCM_U24LE)
00123
00124 PCMDEF(u16be, "PCM unsigned 16-bit big-endian",
00125 AV_NE("uw", NULL), AV_CODEC_ID_PCM_U16BE)
00126
00127 PCMDEF(u16le, "PCM unsigned 16-bit little-endian",
00128 AV_NE(NULL, "uw"), AV_CODEC_ID_PCM_U16LE)
00129
00130 PCMDEF(u8, "PCM unsigned 8-bit",
00131 "ub", AV_CODEC_ID_PCM_U8)
00132
00133 PCMDEF(alaw, "PCM A-law",
00134 "al", AV_CODEC_ID_PCM_ALAW)
00135
00136 PCMDEF(mulaw, "PCM mu-law",
00137 "ul", AV_CODEC_ID_PCM_MULAW)