]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/pcmdec.c
mxfdec: Fix inferred misuses of enums
[ffmpeg] / libavformat / pcmdec.c
index 178c251f140b035e44724c5ea83b1fc8df0a9ca9..30f69d3ff05878b0705d856b58baf5e1dba5b7dc 100644 (file)
@@ -20,7 +20,7 @@
  */
 
 #include "avformat.h"
-#include "rawdec.h"
+#include "internal.h"
 #include "pcm.h"
 #include "libavutil/log.h"
 #include "libavutil/opt.h"
 
 #define RAW_SAMPLES     1024
 
-static int raw_read_packet(AVFormatContext *s, AVPacket *pkt)
+typedef struct PCMAudioDemuxerContext {
+    AVClass *class;
+    int sample_rate;
+    int channels;
+} PCMAudioDemuxerContext;
+
+static int pcm_read_header(AVFormatContext *s)
+{
+    PCMAudioDemuxerContext *s1 = s->priv_data;
+    AVStream *st;
+
+    st = avformat_new_stream(s, NULL);
+    if (!st)
+        return AVERROR(ENOMEM);
+
+
+    st->codec->codec_type  = AVMEDIA_TYPE_AUDIO;
+    st->codec->codec_id    = s->iformat->raw_codec_id;
+    st->codec->sample_rate = s1->sample_rate;
+    st->codec->channels    = s1->channels;
+
+    st->codec->bits_per_coded_sample =
+        av_get_bits_per_sample(st->codec->codec_id);
+
+    av_assert0(st->codec->bits_per_coded_sample > 0);
+
+    st->codec->block_align =
+        st->codec->bits_per_coded_sample * st->codec->channels / 8;
+
+    avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
+    return 0;
+}
+
+static int pcm_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
     int ret, size, bps;
     //    AVStream *st = s->streams[0];
@@ -51,8 +84,8 @@ static int raw_read_packet(AVFormatContext *s, AVPacket *pkt)
 }
 
 static const AVOption pcm_options[] = {
-    { "sample_rate", "", offsetof(RawAudioDemuxerContext, sample_rate), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
-    { "channels",    "", offsetof(RawAudioDemuxerContext, channels),    AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
+    { "sample_rate", "", offsetof(PCMAudioDemuxerContext, sample_rate), AV_OPT_TYPE_INT, {.i64 = 44100}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
+    { "channels",    "", offsetof(PCMAudioDemuxerContext, channels),    AV_OPT_TYPE_INT, {.i64 = 1}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
     { NULL },
 };
 
@@ -66,9 +99,9 @@ static const AVClass name_ ## _demuxer_class = {            \
 AVInputFormat ff_pcm_ ## name_ ## _demuxer = {              \
     .name           = #name_,                               \
     .long_name      = NULL_IF_CONFIG_SMALL(long_name_),     \
-    .priv_data_size = sizeof(RawAudioDemuxerContext),       \
-    .read_header    = ff_raw_read_header,                   \
-    .read_packet    = raw_read_packet,                      \
+    .priv_data_size = sizeof(PCMAudioDemuxerContext),       \
+    .read_header    = pcm_read_header,                      \
+    .read_packet    = pcm_read_packet,                      \
     .read_seek      = ff_pcm_read_seek,                     \
     .flags          = AVFMT_GENERIC_INDEX,                  \
     .extensions     = ext,                                  \