Advertisement
Guest User

Initial patch to add support for DVDNAV packets to FFMPEG

a guest
Feb 16th, 2013
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 8.15 KB | None | 0 0
  1. diff --git a/mythtv/external/FFmpeg/libavcodec/avcodec.h b/mythtv/external/FFmpeg/libavcodec/avcodec.h
  2. index c6a4812..45d2539 100644
  3. --- a/mythtv/external/FFmpeg/libavcodec/avcodec.h
  4. +++ b/mythtv/external/FFmpeg/libavcodec/avcodec.h
  5. @@ -457,6 +457,9 @@ enum AVCodecID {
  6.      /* DSMCC codec */
  7.      AV_CODEC_ID_DSMCC_B,
  8.  
  9. +    /* PRIVATE_STREAM_2 codec (DVD NAV packets) */
  10. +    AV_CODEC_ID_PRIVATE_STREAM_2,
  11. +
  12.      /* other specific kind of codecs (generally used for attachments) */
  13.      AV_CODEC_ID_FIRST_UNKNOWN = 0x18000,           ///< A dummy ID pointing at the start of various fake codecs.
  14.      AV_CODEC_ID_TTF = 0x18000,
  15. diff --git a/mythtv/external/FFmpeg/libavcodec/utils-mythtv.c b/mythtv/external/FFmpeg/libavcodec/utils-mythtv.c
  16. index b578c6d..16f0b44 100644
  17. --- a/mythtv/external/FFmpeg/libavcodec/utils-mythtv.c
  18. +++ b/mythtv/external/FFmpeg/libavcodec/utils-mythtv.c
  19. @@ -212,6 +212,8 @@ const char *ff_codec_id_string(enum CodecID codec_id)
  20.  
  21.          case AV_CODEC_ID_DSMCC_B:          return "DSMCC_B";
  22.  
  23. +        case AV_CODEC_ID_PRIVATE_STREAM_2: return "PRIVATE_STREAM_2";
  24. +
  25.          case AV_CODEC_ID_MPEG2TS:          return "MPEG2TS";
  26.  
  27.              /* Attachment codecs */
  28. diff --git a/mythtv/external/FFmpeg/libavformat/mpeg.c b/mythtv/external/FFmpeg/libavformat/mpeg.c
  29. index fbea0f7..b2eb2bf 100644
  30. --- a/mythtv/external/FFmpeg/libavformat/mpeg.c
  31. +++ b/mythtv/external/FFmpeg/libavformat/mpeg.c
  32. @@ -239,23 +239,6 @@ static int mpegps_read_pes_header(AVFormatContext *s,
  33.          avio_skip(s->pb, avio_rb16(s->pb));
  34.          goto redo;
  35.      }
  36. -    if (startcode == PRIVATE_STREAM_2) {
  37. -        len = avio_rb16(s->pb);
  38. -        if (!m->sofdec) {
  39. -            while (len-- >= 6) {
  40. -                if (avio_r8(s->pb) == 'S') {
  41. -                    uint8_t buf[5];
  42. -                    avio_read(s->pb, buf, sizeof(buf));
  43. -                    m->sofdec = !memcmp(buf, "ofdec", 5);
  44. -                    len -= sizeof(buf);
  45. -                    break;
  46. -                }
  47. -            }
  48. -            m->sofdec -= !m->sofdec;
  49. -        }
  50. -        avio_skip(s->pb, len);
  51. -        goto redo;
  52. -    }
  53.      if (startcode == PROGRAM_STREAM_MAP) {
  54.          mpegps_psm_parse(m, s->pb);
  55.          goto redo;
  56. @@ -264,7 +247,9 @@ static int mpegps_read_pes_header(AVFormatContext *s,
  57.      /* find matching stream */
  58.      if (!((startcode >= 0x1c0 && startcode <= 0x1df) ||
  59.            (startcode >= 0x1e0 && startcode <= 0x1ef) ||
  60. -          (startcode == 0x1bd) || (startcode == 0x1fd)))
  61. +          (startcode == 0x1bd) ||
  62. +          (startcode == PRIVATE_STREAM_2) ||
  63. +          (startcode == 0x1fd)))
  64.          goto redo;
  65.      if (ppos) {
  66.          *ppos = avio_tell(s->pb) - 4;
  67. @@ -272,79 +257,82 @@ static int mpegps_read_pes_header(AVFormatContext *s,
  68.      len = avio_rb16(s->pb);
  69.      pts =
  70.      dts = AV_NOPTS_VALUE;
  71. -    /* stuffing */
  72. -    for(;;) {
  73. -        if (len < 1)
  74. -            goto error_redo;
  75. -        c = avio_r8(s->pb);
  76. -        len--;
  77. -        /* XXX: for mpeg1, should test only bit 7 */
  78. -        if (c != 0xff)
  79. -            break;
  80. -    }
  81. -    if ((c & 0xc0) == 0x40) {
  82. -        /* buffer scale & size */
  83. -        avio_r8(s->pb);
  84. -        c = avio_r8(s->pb);
  85. -        len -= 2;
  86. -    }
  87. -    if ((c & 0xe0) == 0x20) {
  88. -        dts = pts = get_pts(s->pb, c);
  89. -        len -= 4;
  90. -        if (c & 0x10){
  91. -            dts = get_pts(s->pb, -1);
  92. -            len -= 5;
  93. +    if (startcode != PRIVATE_STREAM_2)
  94. +    {
  95. +        /* stuffing */
  96. +        for(;;) {
  97. +            if (len < 1)
  98. +                goto error_redo;
  99. +            c = avio_r8(s->pb);
  100. +            len--;
  101. +            /* XXX: for mpeg1, should test only bit 7 */
  102. +            if (c != 0xff)
  103. +                break;
  104. +        }
  105. +        if ((c & 0xc0) == 0x40) {
  106. +            /* buffer scale & size */
  107. +            avio_r8(s->pb);
  108. +            c = avio_r8(s->pb);
  109. +            len -= 2;
  110.          }
  111. -    } else if ((c & 0xc0) == 0x80) {
  112. -        /* mpeg 2 PES */
  113. -        flags = avio_r8(s->pb);
  114. -        header_len = avio_r8(s->pb);
  115. -        len -= 2;
  116. -        if (header_len > len)
  117. -            goto error_redo;
  118. -        len -= header_len;
  119. -        if (flags & 0x80) {
  120. -            dts = pts = get_pts(s->pb, -1);
  121. -            header_len -= 5;
  122. -            if (flags & 0x40) {
  123. +        if ((c & 0xe0) == 0x20) {
  124. +            dts = pts = get_pts(s->pb, c);
  125. +            len -= 4;
  126. +            if (c & 0x10){
  127.                  dts = get_pts(s->pb, -1);
  128. +                len -= 5;
  129. +            }
  130. +        } else if ((c & 0xc0) == 0x80) {
  131. +            /* mpeg 2 PES */
  132. +            flags = avio_r8(s->pb);
  133. +            header_len = avio_r8(s->pb);
  134. +            len -= 2;
  135. +            if (header_len > len)
  136. +                goto error_redo;
  137. +            len -= header_len;
  138. +            if (flags & 0x80) {
  139. +                dts = pts = get_pts(s->pb, -1);
  140.                  header_len -= 5;
  141. +                if (flags & 0x40) {
  142. +                    dts = get_pts(s->pb, -1);
  143. +                    header_len -= 5;
  144. +                }
  145.              }
  146. -        }
  147. -        if (flags & 0x3f && header_len == 0){
  148. -            flags &= 0xC0;
  149. -            av_log(s, AV_LOG_WARNING, "Further flags set but no bytes left\n");
  150. -        }
  151. -        if (flags & 0x01) { /* PES extension */
  152. -            pes_ext = avio_r8(s->pb);
  153. -            header_len--;
  154. -            /* Skip PES private data, program packet sequence counter and P-STD buffer */
  155. -            skip = (pes_ext >> 4) & 0xb;
  156. -            skip += skip & 0x9;
  157. -            if (pes_ext & 0x40 || skip > header_len){
  158. -                av_log(s, AV_LOG_WARNING, "pes_ext %X is invalid\n", pes_ext);
  159. -                pes_ext=skip=0;
  160. +            if (flags & 0x3f && header_len == 0){
  161. +                flags &= 0xC0;
  162. +                av_log(s, AV_LOG_WARNING, "Further flags set but no bytes left\n");
  163.              }
  164. -            avio_skip(s->pb, skip);
  165. -            header_len -= skip;
  166. -
  167. -            if (pes_ext & 0x01) { /* PES extension 2 */
  168. -                ext2_len = avio_r8(s->pb);
  169. +            if (flags & 0x01) { /* PES extension */
  170. +                pes_ext = avio_r8(s->pb);
  171.                  header_len--;
  172. -                if ((ext2_len & 0x7f) > 0) {
  173. -                    id_ext = avio_r8(s->pb);
  174. -                    if ((id_ext & 0x80) == 0)
  175. -                        startcode = ((startcode & 0xff) << 8) | id_ext;
  176. +                /* Skip PES private data, program packet sequence counter and P-STD buffer */
  177. +                skip = (pes_ext >> 4) & 0xb;
  178. +                skip += skip & 0x9;
  179. +                if (pes_ext & 0x40 || skip > header_len){
  180. +                    av_log(s, AV_LOG_WARNING, "pes_ext %X is invalid\n", pes_ext);
  181. +                    pes_ext=skip=0;
  182. +                }
  183. +                avio_skip(s->pb, skip);
  184. +                header_len -= skip;
  185. +
  186. +                if (pes_ext & 0x01) { /* PES extension 2 */
  187. +                    ext2_len = avio_r8(s->pb);
  188.                      header_len--;
  189. +                    if ((ext2_len & 0x7f) > 0) {
  190. +                        id_ext = avio_r8(s->pb);
  191. +                        if ((id_ext & 0x80) == 0)
  192. +                            startcode = ((startcode & 0xff) << 8) | id_ext;
  193. +                        header_len--;
  194. +                    }
  195.                  }
  196.              }
  197. +            if(header_len < 0)
  198. +                goto error_redo;
  199. +            avio_skip(s->pb, header_len);
  200.          }
  201. -        if(header_len < 0)
  202. -            goto error_redo;
  203. -        avio_skip(s->pb, header_len);
  204. +        else if( c!= 0xf )
  205. +            goto redo;
  206.      }
  207. -    else if( c!= 0xf )
  208. -        goto redo;
  209.  
  210.      if (startcode == PRIVATE_STREAM_1) {
  211.          startcode = avio_r8(s->pb);
  212. @@ -448,6 +436,9 @@ static int mpegps_read_packet(AVFormatContext *s,
  213.          else
  214.              request_probe= 1;
  215.          type = AVMEDIA_TYPE_VIDEO;
  216. +    } else if (startcode == PRIVATE_STREAM_2) {
  217. +        type = AVMEDIA_TYPE_DATA;
  218. +        codec_id = AV_CODEC_ID_PRIVATE_STREAM_2;
  219.      } else if (startcode >= 0x1c0 && startcode <= 0x1df) {
  220.          type = AVMEDIA_TYPE_AUDIO;
  221.          codec_id = m->sofdec > 0 ? AV_CODEC_ID_ADPCM_ADX : AV_CODEC_ID_MP2;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement