Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] avformat/pcmdec: add pts and dts calculation for pcmdec
@ 2024-05-14 11:33 Shiqi Zhu
  2024-05-14 11:40 ` Andreas Rheinhardt
  0 siblings, 1 reply; 5+ messages in thread
From: Shiqi Zhu @ 2024-05-14 11:33 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Shiqi Zhu

Signed-off-by: Shiqi Zhu <hiccupzhu@gmail.com>
---
 libavformat/pcmdec.c | 37 +++++++++++++++++++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)

diff --git a/libavformat/pcmdec.c b/libavformat/pcmdec.c
index 2f6508b75a..d879aefaad 100644
--- a/libavformat/pcmdec.c
+++ b/libavformat/pcmdec.c
@@ -36,6 +36,7 @@ typedef struct PCMAudioDemuxerContext {
     AVClass *class;
     int sample_rate;
     AVChannelLayout ch_layout;
+    int64_t nb_samples;
 } PCMAudioDemuxerContext;
 
 static int pcm_read_header(AVFormatContext *s)
@@ -46,6 +47,7 @@ static int pcm_read_header(AVFormatContext *s)
     uint8_t *mime_type = NULL;
     int ret;
 
+    s1->nb_samples = 0;
     st = avformat_new_stream(s, NULL);
     if (!st)
         return AVERROR(ENOMEM);
@@ -104,6 +106,37 @@ static int pcm_read_header(AVFormatContext *s)
     return 0;
 }
 
+static int pcm_dec_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+    PCMAudioDemuxerContext *s1 = s->priv_data;
+    AVCodecParameters *par = s->streams[0]->codecpar;
+    int ret;
+
+    ret = ff_pcm_read_packet(s, pkt);
+    if (ret < 0)
+        return ret;
+
+    pkt->time_base = s->streams[0]->time_base;
+    pkt->dts = pkt->pts = s1->nb_samples;
+    s1->nb_samples += pkt->size / par->block_align;
+
+    return ret;
+}
+
+static int pcm_dec_read_seek(AVFormatContext *s,
+                             int stream_index, int64_t timestamp, int flags)
+{
+    PCMAudioDemuxerContext *s1 = s->priv_data;
+    int ret;
+
+    ret = ff_pcm_read_seek(s, stream_index, timestamp, flags);
+    if (ret < 0)
+        return ret;
+
+    s1->nb_samples = ffstream(s->streams[0])->cur_dts;
+    return ret;
+}
+
 static const AVOption pcm_options[] = {
     { "sample_rate", "", offsetof(PCMAudioDemuxerContext, sample_rate), AV_OPT_TYPE_INT, {.i64 = 44100}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
     { "ch_layout",   "", offsetof(PCMAudioDemuxerContext, ch_layout),   AV_OPT_TYPE_CHLAYOUT, {.str = "mono"}, 0, 0, AV_OPT_FLAG_DECODING_PARAM },
@@ -126,8 +159,8 @@ const FFInputFormat ff_pcm_ ## name_ ## _demuxer = {        \
     .p.priv_class   = &pcm_demuxer_class,                   \
     .priv_data_size = sizeof(PCMAudioDemuxerContext),       \
     .read_header    = pcm_read_header,                      \
-    .read_packet    = ff_pcm_read_packet,                   \
-    .read_seek      = ff_pcm_read_seek,                     \
+    .read_packet    = pcm_dec_read_packet,                  \
+    .read_seek      = pcm_dec_read_seek,                    \
     .raw_codec_id   = codec,                                \
     __VA_ARGS__                                             \
 };
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-05-15 11:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-14 11:33 [FFmpeg-devel] [PATCH] avformat/pcmdec: add pts and dts calculation for pcmdec Shiqi Zhu
2024-05-14 11:40 ` Andreas Rheinhardt
2024-05-15  1:32   ` Hiccup Zhu
2024-05-15  1:39     ` Andreas Rheinhardt
2024-05-15 11:48       ` Hiccup Zhu

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git