[vlc-commits] [Git][videolan/vlc][master] 6 commits: avformat: add a helper to read stream side data
Steve Lhomme (@robUx4)
gitlab at videolan.org
Sat Jan 18 15:48:23 UTC 2025
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
d3f5c874 by Steve Lhomme at 2025-01-18T15:30:30+00:00
avformat: add a helper to read stream side data
av_packet_side_data_get() was introduced in lavc 60.29.100 [^1].
av_stream_get_side_data() is deprecated and will be removed in the future.
[^1] https://github.com/FFmpeg/FFmpeg/commit/74279227dd28d01b447edb8e617a545982171c2c
- - - - -
de0cf629 by Steve Lhomme at 2025-01-18T15:30:30+00:00
avformat: use av_packet_side_data_get() instead of deprecated av_stream_get_side_data()
- - - - -
27e327e7 by Steve Lhomme at 2025-01-18T15:30:30+00:00
avformat: pass a const AVStream in side data getters
- - - - -
0e208650 by Steve Lhomme at 2025-01-18T15:30:30+00:00
avformat: use a flag to tell if the matrix is flipped
If it's flipped, it's modifying the source matrix inside the codec
which doesn't seem right...
- - - - -
53858f99 by Steve Lhomme at 2025-01-18T15:30:30+00:00
avformat: get the palette side data
- - - - -
656953f5 by Steve Lhomme at 2025-01-18T15:30:30+00:00
avformat: fix warning on value comparison
- - - - -
1 changed file:
- modules/demux/avformat/demux.c
Changes:
=====================================
modules/demux/avformat/demux.c
=====================================
@@ -117,20 +117,32 @@ static vlc_fourcc_t CodecTagToFourcc( uint32_t codec_tag )
#endif
}
+static inline void* GetStreamSideData(const AVStream *s, enum AVPacketSideDataType type)
+{
+#if LIBAVCODEC_VERSION_CHECK( 60, 29, 100 )
+ const AVCodecParameters *cp = s->codecpar;
+ const AVPacketSideData *psd =
+ av_packet_side_data_get(cp->coded_side_data, cp->nb_coded_side_data, type);
+ return psd ? psd->data : NULL;
+#else
+ return av_stream_get_side_data(s, type, NULL);
+#endif
+}
+
/*****************************************************************************
* Open
*****************************************************************************/
-static void get_rotation(es_format_t *fmt, AVStream *s)
+static void get_rotation(es_format_t *fmt, const AVStream *s)
{
char const *kRotateKey = "rotate";
AVDictionaryEntry *rotation = av_dict_get(s->metadata, kRotateKey, NULL, 0);
long angle = 0;
- int32_t *matrix = (int32_t *)av_stream_get_side_data(s, AV_PKT_DATA_DISPLAYMATRIX, NULL);
+ int32_t *matrix = GetStreamSideData(s, AV_PKT_DATA_DISPLAYMATRIX);
if( matrix ) {
- int64_t det = (int64_t)matrix[0] * matrix[4] - (int64_t)matrix[1] * matrix[3];
- if (det < 0) {
+ bool flipped = (int64_t)matrix[0] * matrix[4] < (int64_t)matrix[1] * matrix[3];
+ if (flipped) {
/* Flip the matrix to decouple flip and rotation operations.
* Always assume an horizontal flip for simplicity,
* it can be changed later if rotation is 180º. */
@@ -142,7 +154,7 @@ static void get_rotation(es_format_t *fmt, AVStream *s)
fmt->video.orientation = ORIENT_ROTATED_270;
else if (angle > 135 || angle < -135) {
- if (det < 0)
+ if (flipped)
fmt->video.orientation = ORIENT_VFLIPPED;
else
fmt->video.orientation = ORIENT_ROTATED_180;
@@ -154,7 +166,7 @@ static void get_rotation(es_format_t *fmt, AVStream *s)
fmt->video.orientation = ORIENT_NORMAL;
/* Flip is already applied to the 180º case. */
- if (det < 0 && !(angle > 135 || angle < -135)) {
+ if (flipped && !(angle > 135 || angle < -135)) {
video_transform_t transform = (video_transform_t)fmt->video.orientation;
/* Flip first then rotate */
fmt->video.orientation = ORIENT_HFLIPPED;
@@ -178,12 +190,11 @@ static void get_rotation(es_format_t *fmt, AVStream *s)
}
}
-static void get_dovi_config(es_format_t *fmt, AVStream *s)
+static void get_dovi_config(es_format_t *fmt, const AVStream *s)
{
#if LIBAVUTIL_VERSION_CHECK( 57, 16, 100 )
- AVDOVIDecoderConfigurationRecord *cfg =
- (AVDOVIDecoderConfigurationRecord *)
- av_stream_get_side_data(s, AV_PKT_DATA_DOVI_CONF, NULL);
+ const AVDOVIDecoderConfigurationRecord *cfg =
+ GetStreamSideData(s, AV_PKT_DATA_DOVI_CONF);
if (!cfg)
return;
@@ -197,6 +208,19 @@ static void get_dovi_config(es_format_t *fmt, AVStream *s)
#endif
}
+static void get_palette(es_format_t *fmt, const AVStream *s)
+{
+ const uint8_t *pal = GetStreamSideData(s, AV_PKT_DATA_PALETTE);
+ if (pal) {
+ video_palette_t *p_palette = fmt->video.p_palette;
+ for (size_t i=0; i<ARRAY_SIZE(p_palette->palette); i++)
+ {
+ memcpy(p_palette->palette[i], pal, sizeof(p_palette->palette[0]));
+ pal += sizeof(p_palette->palette[0]);
+ }
+ }
+}
+
static AVDictionary * BuildAVOptions( demux_t *p_demux )
{
char *psz_opts = var_InheritString( p_demux, "avformat-options" );
@@ -516,8 +540,8 @@ int avformat_OpenDemux( vlc_object_t *p_this )
get_rotation(&es_fmt, s);
get_dovi_config(&es_fmt, s);
+ get_palette(&es_fmt, s);
-# warning FIXME: implement palette transmission
psz_type = "video";
AVRational rate;
@@ -817,14 +841,15 @@ static int Demux( demux_t *p_demux )
// handle extra data change, this can happen for FLV
#if LIBAVUTIL_VERSION_MAJOR < 57
- int side_data_size;
+# define EXTRA_SIZE_TYPE int
#else
- size_t side_data_size;
+# define EXTRA_SIZE_TYPE size_t
#endif
+ EXTRA_SIZE_TYPE side_data_size;
uint8_t *side_data = av_packet_get_side_data( &pkt, AV_PKT_DATA_NEW_EXTRADATA, &side_data_size );
if( side_data_size > 0 ) {
// ignore new extradata which is the same as previous version
- if( side_data_size != p_track->es_format.i_extra ||
+ if( side_data_size != (EXTRA_SIZE_TYPE)p_track->es_format.i_extra ||
memcmp( side_data, p_track->es_format.p_extra, side_data_size ) != 0 )
{
msg_Warn( p_demux, "New extra data found, seek may not work as expected" );
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/5db139a9ba3f89aaad22fb5f0c520fa545a4de4d...656953f52b97b8f06c5a65045f9afce216a5b1ed
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/5db139a9ba3f89aaad22fb5f0c520fa545a4de4d...656953f52b97b8f06c5a65045f9afce216a5b1ed
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list