Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame^] | 1 | From 0571bb4f1a6e1934ee7e093ce7aa517b9bac8e6a Mon Sep 17 00:00:00 2001 |
| 2 | From: Awais Belal <awais_belal@mentor.com> |
| 3 | Date: Sun, 17 Jan 2016 14:46:10 +0500 |
| 4 | Subject: [PATCH] demux_ogg: partially port libtheora glue code to Theora 1.0 |
| 5 | API |
| 6 | |
| 7 | This partially backports the following commit to allow building |
| 8 | with gcc-5.x and otherwise fails to find the definition of |
| 9 | the _ilog function the way it is used. |
| 10 | |
| 11 | https://github.com/pigoz/mplayer-svn/commit/85e51408cd00979fc209da8e3a39b6f0e7f325bc |
| 12 | |
| 13 | Signed-off-by: Awais Belal <awais_belal@mentor.com> |
| 14 | --- |
| 15 | libmpdemux/demux_ogg.c | 52 ++++++++++++++++++++++++++------------------------ |
| 16 | 1 file changed, 27 insertions(+), 25 deletions(-) |
| 17 | |
| 18 | diff --git a/libmpdemux/demux_ogg.c b/libmpdemux/demux_ogg.c |
| 19 | index 9eea061..9144426 100644 |
| 20 | --- a/libmpdemux/demux_ogg.c |
| 21 | +++ b/libmpdemux/demux_ogg.c |
| 22 | @@ -50,8 +50,7 @@ |
| 23 | #endif |
| 24 | |
| 25 | #ifdef CONFIG_OGGTHEORA |
| 26 | -#include <theora/theora.h> |
| 27 | -int _ilog (unsigned int); /* defined in many places in theora/lib/ */ |
| 28 | +#include <theora/theoradec.h> |
| 29 | #endif |
| 30 | |
| 31 | #define BLOCK_SIZE 4096 |
| 32 | @@ -62,9 +61,10 @@ int _ilog (unsigned int); /* defined in many places in theora/lib/ */ |
| 33 | */ |
| 34 | #ifdef CONFIG_OGGTHEORA |
| 35 | typedef struct theora_struct_st { |
| 36 | - theora_state st; |
| 37 | - theora_comment cc; |
| 38 | - theora_info inf; |
| 39 | + th_setup_info *tsi; |
| 40 | + th_dec_ctx *tctx; |
| 41 | + th_comment tc; |
| 42 | + th_info ti; |
| 43 | } theora_struct_t; |
| 44 | #endif |
| 45 | |
| 46 | @@ -117,7 +117,7 @@ typedef struct ogg_stream { |
| 47 | float samplerate; /// granulpos 2 time |
| 48 | int64_t lastpos; |
| 49 | int32_t lastsize; |
| 50 | - int keyframe_frequency_force; |
| 51 | + int keyframe_granule_shift; |
| 52 | |
| 53 | // Logical stream state |
| 54 | ogg_stream_state stream; |
| 55 | @@ -300,11 +300,10 @@ static unsigned char *demux_ogg_read_packet(ogg_stream_t *os, ogg_packet *pack, |
| 56 | have theora_state st, until all header packets were passed to the |
| 57 | decoder. */ |
| 58 | if (!pack->bytes || !(*data&0x80)) { |
| 59 | - int keyframe_granule_shift = _ilog(os->keyframe_frequency_force - 1); |
| 60 | - int64_t iframemask = (1 << keyframe_granule_shift) - 1; |
| 61 | + int64_t iframemask = iframemask = (1 << os->keyframe_granule_shift) - 1; |
| 62 | |
| 63 | if (pack->granulepos >= 0) { |
| 64 | - os->lastpos = pack->granulepos >> keyframe_granule_shift; |
| 65 | + os->lastpos = pack->granulepos >> os->keyframe_granule_shift; |
| 66 | os->lastpos += pack->granulepos & iframemask; |
| 67 | *keyframe = (pack->granulepos & iframemask) == 0; |
| 68 | } else { |
| 69 | @@ -888,14 +887,15 @@ int demux_ogg_open(demuxer_t *demuxer) |
| 70 | #ifdef CONFIG_OGGTHEORA |
| 71 | } else if (pack.bytes >= 7 && !strncmp (&pack.packet[1], "theora", 6)) { |
| 72 | int errorCode = 0; |
| 73 | - theora_info inf; |
| 74 | - theora_comment cc; |
| 75 | + th_info ti; |
| 76 | + th_comment tc; |
| 77 | + th_setup_info *tsi = NULL; |
| 78 | |
| 79 | - theora_info_init (&inf); |
| 80 | - theora_comment_init (&cc); |
| 81 | + th_info_init (&ti); |
| 82 | + th_comment_init (&tc); |
| 83 | |
| 84 | - errorCode = theora_decode_header (&inf, &cc, &pack); |
| 85 | - if (errorCode) { |
| 86 | + errorCode = th_decode_headerin(&ti, &tc, &tsi, &pack); |
| 87 | + if (errorCode < 0) { |
| 88 | mp_msg(MSGT_DEMUX, MSGL_ERR, |
| 89 | "Theora header parsing failed: %i \n", errorCode); |
| 90 | } else { |
| 91 | @@ -904,30 +904,32 @@ int demux_ogg_open(demuxer_t *demuxer) |
| 92 | sh_v->bih = calloc(1, sizeof(*sh_v->bih)); |
| 93 | sh_v->bih->biSize = sizeof(*sh_v->bih); |
| 94 | sh_v->bih->biCompression = sh_v->format = FOURCC_THEORA; |
| 95 | - sh_v->fps = ((double)inf.fps_numerator) / (double)inf.fps_denominator; |
| 96 | - sh_v->frametime = ((double)inf.fps_denominator) / (double)inf.fps_numerator; |
| 97 | - sh_v->disp_w = sh_v->bih->biWidth = inf.frame_width; |
| 98 | - sh_v->disp_h = sh_v->bih->biHeight = inf.frame_height; |
| 99 | + sh_v->fps = ((double)ti.fps_numerator) / (double)ti.fps_denominator; |
| 100 | + sh_v->frametime = ((double)ti.fps_denominator) / (double)ti.fps_numerator; |
| 101 | + sh_v->i_bps = ti.target_bitrate / 8; |
| 102 | + sh_v->disp_w = sh_v->bih->biWidth = ti.frame_width; |
| 103 | + sh_v->disp_h = sh_v->bih->biHeight = ti.frame_height; |
| 104 | sh_v->bih->biBitCount = 24; |
| 105 | sh_v->bih->biPlanes = 3; |
| 106 | sh_v->bih->biSizeImage = ((sh_v->bih->biBitCount / 8) * sh_v->bih->biWidth * sh_v->bih->biHeight); |
| 107 | ogg_d->subs[ogg_d->num_sub].samplerate = sh_v->fps; |
| 108 | ogg_d->subs[ogg_d->num_sub].theora = 1; |
| 109 | - ogg_d->subs[ogg_d->num_sub].keyframe_frequency_force = inf.keyframe_frequency_force; |
| 110 | + ogg_d->subs[ogg_d->num_sub].keyframe_granule_shift = ti.keyframe_granule_shift; |
| 111 | ogg_d->subs[ogg_d->num_sub].id = n_video; |
| 112 | n_video++; |
| 113 | mp_msg(MSGT_DEMUX, MSGL_INFO, |
| 114 | "[Ogg] stream %d: video (Theora v%d.%d.%d), -vid %d\n", |
| 115 | ogg_d->num_sub, |
| 116 | - (int)inf.version_major, |
| 117 | - (int)inf.version_minor, |
| 118 | - (int)inf.version_subminor, |
| 119 | + (int)ti.version_major, |
| 120 | + (int)ti.version_minor, |
| 121 | + (int)ti.version_subminor, |
| 122 | n_video - 1); |
| 123 | if (mp_msg_test(MSGT_HEADER, MSGL_V)) |
| 124 | print_video_header(sh_v->bih, MSGL_V); |
| 125 | } |
| 126 | - theora_comment_clear(&cc); |
| 127 | - theora_info_clear(&inf); |
| 128 | + th_comment_clear(&tc); |
| 129 | + th_info_clear(&ti); |
| 130 | + th_setup_free(tsi); |
| 131 | #endif /* CONFIG_OGGTHEORA */ |
| 132 | } else if (pack.bytes >= 4 && !strncmp (&pack.packet[0], "fLaC", 4)) { |
| 133 | sh_a = new_sh_audio_aid(demuxer, ogg_d->num_sub, n_audio); |
| 134 | -- |
| 135 | 1.9.1 |
| 136 | |