]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/westwood_aud.c
lavfi: allow audio filters to request a given number of samples.
[ffmpeg] / libavformat / westwood_aud.c
index 79f219874553077c268b9964011903a1873a455d..a7148eb08b716093e1fdb918a323232320bd0821 100644 (file)
 #define AUD_CHUNK_PREAMBLE_SIZE 8
 #define AUD_CHUNK_SIGNATURE 0x0000DEAF
 
-typedef struct WsAudDemuxContext {
-    int audio_channels;
-    int audio_samplerate;
-    int audio_stream_index;
-    int64_t audio_frame_counter;
-} WsAudDemuxContext;
-
 static int wsaud_probe(AVProbeData *p)
 {
     int field;
@@ -88,10 +81,8 @@ static int wsaud_probe(AVProbeData *p)
     return AVPROBE_SCORE_MAX / 2;
 }
 
-static int wsaud_read_header(AVFormatContext *s,
-                             AVFormatParameters *ap)
+static int wsaud_read_header(AVFormatContext *s)
 {
-    WsAudDemuxContext *wsaud = s->priv_data;
     AVIOContext *pb = s->pb;
     AVStream *st;
     unsigned char header[AUD_HEADER_SIZE];
@@ -131,23 +122,17 @@ static int wsaud_read_header(AVFormatContext *s,
     st->codec->channels    = channels;
     st->codec->sample_rate = sample_rate;
 
-    wsaud->audio_channels = channels;
-    wsaud->audio_samplerate = sample_rate;
-    wsaud->audio_stream_index = st->index;
-    wsaud->audio_frame_counter = 0;
-
     return 0;
 }
 
 static int wsaud_read_packet(AVFormatContext *s,
                              AVPacket *pkt)
 {
-    WsAudDemuxContext *wsaud = s->priv_data;
     AVIOContext *pb = s->pb;
     unsigned char preamble[AUD_CHUNK_PREAMBLE_SIZE];
     unsigned int chunk_size;
     int ret = 0;
-    AVStream *st = s->streams[wsaud->audio_stream_index];
+    AVStream *st = s->streams[0];
 
     if (avio_read(pb, preamble, AUD_CHUNK_PREAMBLE_SIZE) !=
         AUD_CHUNK_PREAMBLE_SIZE)
@@ -177,11 +162,9 @@ static int wsaud_read_packet(AVFormatContext *s,
         ret = av_get_packet(pb, pkt, chunk_size);
         if (ret != chunk_size)
             return AVERROR(EIO);
-        pkt->pts = wsaud->audio_frame_counter;
-        pkt->pts /= wsaud->audio_samplerate;
 
         /* 2 samples/byte, 1 or 2 samples per frame depending on stereo */
-        wsaud->audio_frame_counter += (chunk_size * 2) / wsaud->audio_channels;
+        pkt->duration = (chunk_size * 2) / st->codec->channels;
     }
     pkt->stream_index = st->index;
 
@@ -191,7 +174,6 @@ static int wsaud_read_packet(AVFormatContext *s,
 AVInputFormat ff_wsaud_demuxer = {
     .name           = "wsaud",
     .long_name      = NULL_IF_CONFIG_SMALL("Westwood Studios audio format"),
-    .priv_data_size = sizeof(WsAudDemuxContext),
     .read_probe     = wsaud_probe,
     .read_header    = wsaud_read_header,
     .read_packet    = wsaud_read_packet,