From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> To: ffmpeg-devel@ffmpeg.org Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Subject: [FFmpeg-devel] [PATCH] avformat/matroskadec: Output palette as stream side data Date: Thu, 5 Oct 2023 14:36:52 +0200 Message-ID: <AS8P250MB0744AE847962511BE05158218FCAA@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> (raw) This is simpler implementation-wise (it avoids an almost-always-false check in read_packet and decreases sizeof(MatroskaTrack) by about 2/3) and makes the side-data available directly after read_header. It also fixes the Matroska analog of ticket #10602: If a Matroska track has a palette, said palette will be attached as side-data to the first packet of said track and most likely, this is one read during avformat_find_stream_info(). Yet if this packet is discarded because of a seek performed immediately after avformat_find_stream_info(), the information about the global palette will never reach the user. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- Ticket #10602 can unfortunately not be fixed in this way, because avi allows to update the palette mid-stream, so that the palette contained in extradata must not be exported via global side data due to the semantics of the latter. libavformat/matroskadec.c | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 941c0bcdc9..74f3fc7ae7 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -285,9 +285,6 @@ typedef struct MatroskaTrack { int needs_decoding; uint64_t max_block_additional_id; EbmlList block_addition_mappings; - - uint32_t palette[AVPALETTE_COUNT]; - int has_palette; } MatroskaTrack; typedef struct MatroskaAttachment { @@ -2852,7 +2849,8 @@ static int mka_parse_audio(MatroskaTrack *track, AVStream *st, } /* Performs the codec-specific part of parsing a video track. */ -static int mkv_parse_video_codec(MatroskaTrack *track, AVCodecParameters *par, +static int mkv_parse_video_codec(AVStream *st, MatroskaTrack *track, + AVCodecParameters *par, const MatroskaDemuxContext *matroska, int *extradata_offset) { @@ -2886,11 +2884,15 @@ static int mkv_parse_video_codec(MatroskaTrack *track, AVCodecParameters *par, if (track->codec_priv.size >= 86) { FFIOContext b; unsigned bit_depth = AV_RB16(track->codec_priv.data + 82); + uint32_t palette[256] = { 0 }; ffio_init_read_context(&b, track->codec_priv.data, track->codec_priv.size); - if (ff_get_qtpalette(codec_id, &b.pub, track->palette)) { + if (ff_get_qtpalette(codec_id, &b.pub, palette)) { + void *side_data = av_stream_new_side_data(st, AV_PKT_DATA_PALETTE, AVPALETTE_SIZE); + if (!side_data) + return AVERROR(ENOMEM); + memcpy(side_data, palette, AVPALETTE_SIZE); bit_depth &= 0x1F; - track->has_palette = 1; } par->bits_per_coded_sample = bit_depth; } @@ -2934,7 +2936,7 @@ static int mkv_parse_video(MatroskaTrack *track, AVStream *st, if (track->video.color_space.size == 4) par->codec_tag = AV_RL32(track->video.color_space.data); - ret = mkv_parse_video_codec(track, par, matroska, + ret = mkv_parse_video_codec(st, track, par, matroska, extradata_offset); if (ret < 0) return ret; @@ -3398,30 +3400,13 @@ static int matroska_read_header(AVFormatContext *s) /* * Put one packet in an application-supplied AVPacket struct. - * Returns 0 on success or -1 on failure. + * Returns 0 on success or < 0 (most likely AVERROR(EAGAIN) + * if no packet was available. */ static int matroska_deliver_packet(MatroskaDemuxContext *matroska, AVPacket *pkt) { - if (matroska->queue.head) { - MatroskaTrack *tracks = matroska->tracks.elem; - MatroskaTrack *track; - - avpriv_packet_list_get(&matroska->queue, pkt); - track = &tracks[pkt->stream_index]; - if (track->has_palette) { - uint8_t *pal = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE, AVPALETTE_SIZE); - if (!pal) { - av_log(matroska->ctx, AV_LOG_ERROR, "Cannot append palette to packet\n"); - } else { - memcpy(pal, track->palette, AVPALETTE_SIZE); - } - track->has_palette = 0; - } - return 0; - } - - return -1; + return avpriv_packet_list_get(&matroska->queue, pkt); } /* -- 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".
next reply other threads:[~2023-10-05 12:51 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-10-05 12:36 Andreas Rheinhardt [this message] 2023-10-08 16:36 ` Michael Niedermayer 2023-10-08 19:06 ` Andreas Rheinhardt
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=AS8P250MB0744AE847962511BE05158218FCAA@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM \ --to=andreas.rheinhardt@outlook.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
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