Mercurial > libavcodec.hg
comparison dvdsubdec.c @ 4924:4d185d65488c libavcodec
Move dvdsub parser to its own file.
author | diego |
---|---|
date | Sun, 06 May 2007 09:12:10 +0000 |
parents | fe3179006730 |
children | 9f0f022ca8e7 |
comparison
equal
deleted
inserted
replaced
4923:6ae3f99d9a1b | 4924:4d185d65488c |
---|---|
408 dvdsub_init_decoder, | 408 dvdsub_init_decoder, |
409 NULL, | 409 NULL, |
410 dvdsub_close_decoder, | 410 dvdsub_close_decoder, |
411 dvdsub_decode, | 411 dvdsub_decode, |
412 }; | 412 }; |
413 | |
414 /* parser definition */ | |
415 typedef struct DVDSubParseContext { | |
416 uint8_t *packet; | |
417 int packet_len; | |
418 int packet_index; | |
419 } DVDSubParseContext; | |
420 | |
421 static int dvdsub_parse_init(AVCodecParserContext *s) | |
422 { | |
423 return 0; | |
424 } | |
425 | |
426 static int dvdsub_parse(AVCodecParserContext *s, | |
427 AVCodecContext *avctx, | |
428 uint8_t **poutbuf, int *poutbuf_size, | |
429 const uint8_t *buf, int buf_size) | |
430 { | |
431 DVDSubParseContext *pc = s->priv_data; | |
432 | |
433 if (pc->packet_index == 0) { | |
434 if (buf_size < 2) | |
435 return 0; | |
436 pc->packet_len = AV_RB16(buf); | |
437 av_freep(&pc->packet); | |
438 pc->packet = av_malloc(pc->packet_len); | |
439 } | |
440 if (pc->packet) { | |
441 if (pc->packet_index + buf_size <= pc->packet_len) { | |
442 memcpy(pc->packet + pc->packet_index, buf, buf_size); | |
443 pc->packet_index += buf_size; | |
444 if (pc->packet_index >= pc->packet_len) { | |
445 *poutbuf = pc->packet; | |
446 *poutbuf_size = pc->packet_len; | |
447 pc->packet_index = 0; | |
448 return buf_size; | |
449 } | |
450 } else { | |
451 /* erroneous size */ | |
452 pc->packet_index = 0; | |
453 } | |
454 } | |
455 *poutbuf = NULL; | |
456 *poutbuf_size = 0; | |
457 return buf_size; | |
458 } | |
459 | |
460 static void dvdsub_parse_close(AVCodecParserContext *s) | |
461 { | |
462 DVDSubParseContext *pc = s->priv_data; | |
463 av_freep(&pc->packet); | |
464 } | |
465 | |
466 AVCodecParser dvdsub_parser = { | |
467 { CODEC_ID_DVD_SUBTITLE }, | |
468 sizeof(DVDSubParseContext), | |
469 dvdsub_parse_init, | |
470 dvdsub_parse, | |
471 dvdsub_parse_close, | |
472 }; |