]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/rtp_h264.c
Support decoding Avid 1:1x codec, (partially) fixes issue1684.
[ffmpeg] / libavformat / rtp_h264.c
index 7d6f96c6b58d6ebc5efba83f3aef4c64bf1eac71..bc47078c2816e19acfe2fc2d0fe1e6cc26cefd9e 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * RTP H264 Protocol (RFC3984)
- * Copyright (c) 2006 Ryan Martell.
+ * Copyright (c) 2006 Ryan Martell
  *
  * This file is part of FFmpeg.
  *
@@ -20,7 +20,7 @@
  */
 
 /**
-* @file rtp_h264.c
+* @file libavformat/rtp_h264.c
  * @brief H.264 / RTP Code (RFC3984)
  * @author Ryan Martell <rdm4@martellventures.com>
  *
@@ -38,7 +38,7 @@
 
 #include "libavutil/base64.h"
 #include "libavutil/avstring.h"
-#include "libavcodec/bitstream.h"
+#include "libavcodec/get_bits.h"
 #include "avformat.h"
 #include "mpegts.h"
 
@@ -46,7 +46,7 @@
 #include "network.h"
 #include <assert.h>
 
-#include "rtp_internal.h"
+#include "rtpdec.h"
 #include "rtp_h264.h"
 
 /**
@@ -78,7 +78,7 @@ static void sdp_parse_fmtp_config_h264(AVStream * stream,
     assert(h264_data != NULL);
 
     if (!strcmp(attr, "packetization-mode")) {
-        av_log(NULL, AV_LOG_DEBUG, "H.264/RTP Packetization Mode: %d\n", atoi(value));
+        av_log(codec, AV_LOG_DEBUG, "RTP Packetization Mode: %d\n", atoi(value));
         h264_data->packetization_mode = atoi(value);
         /*
            Packetization Mode:
@@ -87,8 +87,8 @@ static void sdp_parse_fmtp_config_h264(AVStream * stream,
            2: Interleaved Mode: 25 (STAP-B), 26 (MTAP16), 27 (MTAP24), 28 (FU-A), and 29 (FU-B) are allowed.
          */
         if (h264_data->packetization_mode > 1)
-            av_log(stream, AV_LOG_ERROR,
-                   "H.264/RTP Interleaved RTP mode is not supported yet.");
+            av_log(codec, AV_LOG_ERROR,
+                   "Interleaved RTP mode is not supported yet.");
     } else if (!strcmp(attr, "profile-level-id")) {
         if (strlen(value) == 6) {
             char buffer[3];
@@ -105,8 +105,8 @@ static void sdp_parse_fmtp_config_h264(AVStream * stream,
             level_idc = strtol(buffer, NULL, 16);
 
             // set the parameters...
-            av_log(NULL, AV_LOG_DEBUG,
-                   "H.264/RTP Profile IDC: %x Profile IOP: %x Level: %x\n",
+            av_log(codec, AV_LOG_DEBUG,
+                   "RTP Profile IDC: %x Profile IOP: %x Level: %x\n",
                    profile_idc, profile_iop, level_idc);
             h264_data->profile_idc = profile_idc;
             h264_data->profile_iop = profile_iop;
@@ -150,16 +150,17 @@ static void sdp_parse_fmtp_config_h264(AVStream * stream,
                     codec->extradata= dest;
                     codec->extradata_size+= sizeof(start_sequence)+packet_size;
                 } else {
-                    av_log(NULL, AV_LOG_ERROR, "H.264/RTP Unable to allocate memory for extradata!");
+                    av_log(codec, AV_LOG_ERROR, "Unable to allocate memory for extradata!");
                 }
             }
         }
-        av_log(NULL, AV_LOG_DEBUG, "H.264/RTP Extradata set to %p (size: %d)!", codec->extradata, codec->extradata_size);
+        av_log(codec, AV_LOG_DEBUG, "Extradata set to %p (size: %d)!", codec->extradata, codec->extradata_size);
     }
 }
 
 // return 0 on packet, no more left, 1 on packet, 1 on partial packet...
-static int h264_handle_packet(PayloadContext *data,
+static int h264_handle_packet(AVFormatContext *ctx,
+                              PayloadContext *data,
                               AVStream *st,
                               AVPacket * pkt,
                               uint32_t * timestamp,
@@ -230,7 +231,7 @@ static int h264_handle_packet(PayloadContext *data,
                             dst+= nal_size;
                         }
                     } else {
-                        av_log(NULL, AV_LOG_ERROR,
+                        av_log(ctx, AV_LOG_ERROR,
                                "nal size exceeds length: %d %d\n", nal_size, src_len);
                     }
 
@@ -239,7 +240,7 @@ static int h264_handle_packet(PayloadContext *data,
                     src_len -= nal_size;
 
                     if (src_len < 0)
-                        av_log(NULL, AV_LOG_ERROR,
+                        av_log(ctx, AV_LOG_ERROR,
                                "Consumed more bytes than we got! (%d)\n", src_len);
                 } while (src_len > 2);      // because there could be rtp padding..
 
@@ -258,7 +259,7 @@ static int h264_handle_packet(PayloadContext *data,
     case 26:                   // MTAP-16
     case 27:                   // MTAP-24
     case 29:                   // FU-B
-        av_log(NULL, AV_LOG_ERROR,
+        av_log(ctx, AV_LOG_ERROR,
                "Unhandled type (%d) (See RFC for implementation details\n",
                type);
         result= -1;
@@ -304,16 +305,18 @@ static int h264_handle_packet(PayloadContext *data,
     case 30:                   // undefined
     case 31:                   // undefined
     default:
-        av_log(NULL, AV_LOG_ERROR, "Undefined type (%d)", type);
+        av_log(ctx, AV_LOG_ERROR, "Undefined type (%d)", type);
         result= -1;
         break;
     }
 
+    pkt->stream_index = st->index;
+
     return result;
 }
 
 /* ---------------- public code */
-static PayloadContext *h264_new_extradata(void)
+static PayloadContext *h264_new_context(void)
 {
     PayloadContext *data =
         av_mallocz(sizeof(PayloadContext) +
@@ -326,7 +329,7 @@ static PayloadContext *h264_new_extradata(void)
     return data;
 }
 
-static void h264_free_extradata(PayloadContext *data)
+static void h264_free_context(PayloadContext *data)
 {
 #ifdef DEBUG
     int ii;
@@ -365,7 +368,7 @@ static int parse_h264_sdp_line(AVFormatContext *s, int st_index,
         while (*p && *p == ' ') p++; // strip spaces.
         while (*p && *p != ' ') p++; // eat protocol identifier
         while (*p && *p == ' ') p++; // strip trailing spaces.
-        while (*p && *p != '-' && (buf1 - dst) < sizeof(buf1) - 1) {
+        while (*p && *p != '-' && (dst - buf1) < sizeof(buf1) - 1) {
             *dst++ = *p++;
         }
         *dst = '\0';
@@ -403,11 +406,11 @@ static int parse_h264_sdp_line(AVFormatContext *s, int st_index,
 This is the structure for expanding on the dynamic rtp protocols (makes everything static. yay!)
 */
 RTPDynamicProtocolHandler ff_h264_dynamic_handler = {
-    "H264",
-    CODEC_TYPE_VIDEO,
-    CODEC_ID_H264,
-    parse_h264_sdp_line,
-    h264_new_extradata,
-    h264_free_extradata,
-    h264_handle_packet
+    .enc_name         = "H264",
+    .codec_type       = CODEC_TYPE_VIDEO,
+    .codec_id         = CODEC_ID_H264,
+    .parse_sdp_a_line = parse_h264_sdp_line,
+    .open             = h264_new_context,
+    .close            = h264_free_context,
+    .parse_packet     = h264_handle_packet
 };