mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2026-10-24 02:09:03 +03:00
avcodec/decode: add a function returning subtitle packet data followed by a 0 byte
Text subtitle decoders parse the packet data as a string, but the padding after it is not required to be zero, and in laced Matroska blocks it holds the next event. The data is copied only when its first padding byte is not 0.
This commit is contained in:
committed by
michaelni
parent
e784547477
commit
7de69e952c
@@ -936,6 +936,18 @@ static int utf8_check(const uint8_t *str)
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char *ff_decode_subtitle_text(AVCodecContext *avctx, const AVPacket *avpkt)
|
||||
{
|
||||
AVPacket *copy = avctx->internal->buffer_pkt;
|
||||
|
||||
if (avpkt->size <= 0 || !avpkt->data[avpkt->size])
|
||||
return avpkt->data;
|
||||
if (av_new_packet(copy, avpkt->size) < 0)
|
||||
return NULL;
|
||||
memcpy(copy->data, avpkt->data, avpkt->size);
|
||||
return copy->data;
|
||||
}
|
||||
|
||||
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
|
||||
int *got_sub_ptr, const AVPacket *avpkt)
|
||||
{
|
||||
@@ -967,8 +979,7 @@ int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
|
||||
sub->pts = av_rescale_q(avpkt->pts,
|
||||
avctx->pkt_timebase, AV_TIME_BASE_Q);
|
||||
ret = ffcodec(avctx->codec)->cb.decode_sub(avctx, sub, got_sub_ptr, pkt);
|
||||
if (pkt == avci->buffer_pkt) // did we recode?
|
||||
av_packet_unref(avci->buffer_pkt);
|
||||
av_packet_unref(avci->buffer_pkt);
|
||||
if (ret < 0) {
|
||||
*got_sub_ptr = 0;
|
||||
avsubtitle_free(sub);
|
||||
|
||||
@@ -241,4 +241,13 @@ int ff_decode_content_light_new_ext(const AVCodecContext *avctx,
|
||||
AVFrameSideData ***sd, int *nb_sd,
|
||||
struct AVContentLightMetadata **clm);
|
||||
|
||||
/**
|
||||
* Get the data of a subtitle packet followed by a 0 byte.
|
||||
*
|
||||
* @return avpkt->data if avpkt->size <= 0 or its first padding byte is 0,
|
||||
* otherwise a copy valid until the decode callback returns,
|
||||
* NULL on allocation failure
|
||||
*/
|
||||
const char *ff_decode_subtitle_text(AVCodecContext *avctx, const AVPacket *avpkt);
|
||||
|
||||
#endif /* AVCODEC_DECODE_H */
|
||||
|
||||
Reference in New Issue
Block a user