Call this new function before decode() to replace the custom and
inconsistant initialization in various decoders.
This function is equivalent to avcodec_get_frame_defaults() for AVFrame.
Signed-off-by: Aurelien Jacobs <aurel@gnuage.org>
| ... | ... |
@@ -62,11 +62,6 @@ int ff_ass_subtitle_header_default(AVCodecContext *avctx) |
| 62 | 62 |
ASS_DEFAULT_ALIGNMENT); |
| 63 | 63 |
} |
| 64 | 64 |
|
| 65 |
-void ff_ass_init(AVSubtitle *sub) |
|
| 66 |
-{
|
|
| 67 |
- memset(sub, 0, sizeof(*sub)); |
|
| 68 |
-} |
|
| 69 |
- |
|
| 70 | 65 |
static int ts_to_string(char *str, int strlen, int ts) |
| 71 | 66 |
{
|
| 72 | 67 |
int h, m, s; |
| ... | ... |
@@ -70,13 +70,6 @@ int ff_ass_subtitle_header(AVCodecContext *avctx, |
| 70 | 70 |
int ff_ass_subtitle_header_default(AVCodecContext *avctx); |
| 71 | 71 |
|
| 72 | 72 |
/** |
| 73 |
- * Initialize an AVSubtitle structure for use with ff_ass_add_rect(). |
|
| 74 |
- * |
|
| 75 |
- * @param sub pointer to the AVSubtitle |
|
| 76 |
- */ |
|
| 77 |
-void ff_ass_init(AVSubtitle *sub); |
|
| 78 |
- |
|
| 79 |
-/** |
|
| 80 | 73 |
* Add an ASS dialog line to an AVSubtitle as a new AVSubtitleRect. |
| 81 | 74 |
* |
| 82 | 75 |
* @param sub pointer to the AVSubtitle |
| ... | ... |
@@ -38,8 +38,6 @@ static int ass_decode_frame(AVCodecContext *avctx, void *data, int *got_sub_ptr, |
| 38 | 38 |
const char *ptr = avpkt->data; |
| 39 | 39 |
int len, size = avpkt->size; |
| 40 | 40 |
|
| 41 |
- ff_ass_init(data); |
|
| 42 |
- |
|
| 43 | 41 |
while (size > 0) {
|
| 44 | 42 |
len = ff_ass_add_rect(data, ptr, 0, 0/* FIXME: duration */, 1); |
| 45 | 43 |
if (len < 0) |
| ... | ... |
@@ -1323,10 +1323,7 @@ static int dvbsub_display_end_segment(AVCodecContext *avctx, const uint8_t *buf, |
| 1323 | 1323 |
int i; |
| 1324 | 1324 |
int offset_x=0, offset_y=0; |
| 1325 | 1325 |
|
| 1326 |
- sub->rects = NULL; |
|
| 1327 |
- sub->start_display_time = 0; |
|
| 1328 | 1326 |
sub->end_display_time = ctx->time_out * 1000; |
| 1329 |
- sub->format = 0; |
|
| 1330 | 1327 |
|
| 1331 | 1328 |
if (display_def) {
|
| 1332 | 1329 |
offset_x = display_def->x; |
| ... | ... |
@@ -357,7 +357,6 @@ static int display_end_segment(AVCodecContext *avctx, void *data, |
| 357 | 357 |
* not been cleared by a subsequent empty display command. |
| 358 | 358 |
*/ |
| 359 | 359 |
|
| 360 |
- memset(sub, 0, sizeof(*sub)); |
|
| 361 | 360 |
// Blank if last object_number was 0. |
| 362 | 361 |
// Note that this may be wrong for more complex subtitles. |
| 363 | 362 |
if (!ctx->presentation.object_number) |
| ... | ... |
@@ -474,6 +474,12 @@ AVFrame *avcodec_alloc_frame(void){
|
| 474 | 474 |
return pic; |
| 475 | 475 |
} |
| 476 | 476 |
|
| 477 |
+static void avcodec_get_subtitle_defaults(AVSubtitle *sub) |
|
| 478 |
+{
|
|
| 479 |
+ memset(sub, 0, sizeof(*sub)); |
|
| 480 |
+ sub->pts = AV_NOPTS_VALUE; |
|
| 481 |
+} |
|
| 482 |
+ |
|
| 477 | 483 |
int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec) |
| 478 | 484 |
{
|
| 479 | 485 |
int ret= -1; |
| ... | ... |
@@ -795,6 +801,7 @@ int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, |
| 795 | 795 |
|
| 796 | 796 |
avctx->pkt = avpkt; |
| 797 | 797 |
*got_sub_ptr = 0; |
| 798 |
+ avcodec_get_subtitle_defaults(sub); |
|
| 798 | 799 |
ret = avctx->codec->decode(avctx, sub, got_sub_ptr, avpkt); |
| 799 | 800 |
if (*got_sub_ptr) |
| 800 | 801 |
avctx->frame_number++; |
| ... | ... |
@@ -55,8 +55,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, |
| 55 | 55 |
int64_t packet_time = 0; |
| 56 | 56 |
GetBitContext gb; |
| 57 | 57 |
|
| 58 |
- memset(sub, 0, sizeof(*sub)); |
|
| 59 |
- |
|
| 60 | 58 |
// check that at least header fits |
| 61 | 59 |
if (buf_size < 27 + 7 * 2 + 4 * 3) {
|
| 62 | 60 |
av_log(avctx, AV_LOG_ERROR, "coded frame too small\n"); |