[FFmpeg-devel] Fix for KLV in mpegts

Submitted by Artyom Lebedev on Dec. 7, 2018, 10:06 a.m.

Details

Message ID 5ec7a975-5a32-68b5-17ac-df00c5e0cb15@gmail.com
State New
Headers show

Commit Message

Artyom Lebedev Dec. 7, 2018, 10:06 a.m.
This fixes bug which prevents from proper muxing-in KLV stream into mpeg-ts.

mpegtsenc.c:1526

     char *side_data = NULL;
     int stream_id = -1;

     side_data = av_packet_get_side_data(pkt,
AV_PKT_DATA_MPEGTS_STREAM_ID,
                                         &side_data_size);
     if (side_data)
         stream_id = side_data[0];

One-byte stream ID is read from "char *" array to integer making it to 
sign-extend which is not correct. Although it writes it correctly to 
stream, since it is treated as one byte again, but it fails with some 
condition checks, e.g. in mpegtsenc.c:1278:

if (stream_id == 0xbd) /* asynchronous KLV */
     pts = dts = AV_NOPTS_VALUE;
stream_id value in such case is 0xffffffbd.

Fix should be changing side_data type from "char *" to "uint8_t *".

Comments

Peter Ross Dec. 7, 2018, 12:27 p.m.
On Fri, Dec 07, 2018 at 12:06:36PM +0200, Artyom Lebedev wrote:
> This fixes bug which prevents from proper muxing-in KLV stream into mpeg-ts.
> 
> mpegtsenc.c:1526
> 
>     char *side_data = NULL;
>     int stream_id = -1;
> 
>     side_data = av_packet_get_side_data(pkt,
> AV_PKT_DATA_MPEGTS_STREAM_ID,
>                                         &side_data_size);
>     if (side_data)
>         stream_id = side_data[0];
> 
> One-byte stream ID is read from "char *" array to integer making it to
> sign-extend which is not correct. Although it writes it correctly to stream,
> since it is treated as one byte again, but it fails with some condition
> checks, e.g. in mpegtsenc.c:1278:
> 
> if (stream_id == 0xbd) /* asynchronous KLV */
>     pts = dts = AV_NOPTS_VALUE;
> stream_id value in such case is 0xffffffbd.
> 
> Fix should be changing side_data type from "char *" to "uint8_t *".

looks good. i will apply if no one else rejects.

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)
Carl Eugen Hoyos Dec. 7, 2018, 12:46 p.m.
2018-12-07 13:27 GMT+01:00, Peter Ross <pross@xvid.org>:
> On Fri, Dec 07, 2018 at 12:06:36PM +0200, Artyom Lebedev wrote:
>> This fixes bug which prevents from proper muxing-in KLV stream into
>> mpeg-ts.
>>
>> mpegtsenc.c:1526
>>
>>     char *side_data = NULL;
>>     int stream_id = -1;
>>
>>     side_data = av_packet_get_side_data(pkt,
>> AV_PKT_DATA_MPEGTS_STREAM_ID,
>>                                         &side_data_size);
>>     if (side_data)
>>         stream_id = side_data[0];
>>
>> One-byte stream ID is read from "char *" array to integer making it to
>> sign-extend which is not correct. Although it writes it correctly to
>> stream,
>> since it is treated as one byte again, but it fails with some condition
>> checks, e.g. in mpegtsenc.c:1278:
>>
>> if (stream_id == 0xbd) /* asynchronous KLV */
>>     pts = dts = AV_NOPTS_VALUE;
>> stream_id value in such case is 0xffffffbd.
>>
>> Fix should be changing side_data type from "char *" to "uint8_t *".
>
> looks good. i will apply if no one else rejects.

Please mention ticket #7597.

Carl Eugen

Patch hide | download patch | download mbox

From d063568a1765f40a79c6dcf44a444e83e0eb0bed Mon Sep 17 00:00:00 2001
From: <vagran.ast@gmail.com>
Date: Fri, 7 Dec 2018 11:48:28 +0200
Subject: [PATCH] Fix bug in mpegts muxer which affects KLV async stream
 generation.

---
 libavformat/mpegtsenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 3339e26..4470b71 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -1523,7 +1523,7 @@  static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
     int64_t dts = pkt->dts, pts = pkt->pts;
     int opus_samples = 0;
     int side_data_size;
-    char *side_data = NULL;
+    uint8_t *side_data = NULL;
     int stream_id = -1;
 
     side_data = av_packet_get_side_data(pkt,
-- 
2.7.4