http: Expose the content location via an AVOption
[ffmpeg.git] / libavformat / rtpdec_h264.c
index d9b2700..5e0169b 100644 (file)
  *                        FU-B packet types)
  */
 
+#include "libavutil/attributes.h"
 #include "libavutil/base64.h"
 #include "libavutil/avstring.h"
 #include "libavcodec/get_bits.h"
 #include "avformat.h"
-#include "mpegts.h"
 
-#include <unistd.h>
 #include "network.h"
 #include <assert.h>
 
@@ -70,7 +69,7 @@ static int sdp_parse_fmtp_config_h264(AVStream *stream,
                                       char *attr, char *value)
 {
     AVCodecContext *codec = stream->codec;
-    assert(codec->codec_id == CODEC_ID_H264);
+    assert(codec->codec_id == AV_CODEC_ID_H264);
     assert(h264_data != NULL);
 
     if (!strcmp(attr, "packetization-mode")) {
@@ -85,7 +84,7 @@ static int sdp_parse_fmtp_config_h264(AVStream *stream,
          */
         if (h264_data->packetization_mode > 1)
             av_log(codec, AV_LOG_ERROR,
-                   "Interleaved RTP mode is not supported yet.");
+                   "Interleaved RTP mode is not supported yet.\n");
     } else if (!strcmp(attr, "profile-level-id")) {
         if (strlen(value) == 6) {
             char buffer[3];
@@ -114,7 +113,7 @@ static int sdp_parse_fmtp_config_h264(AVStream *stream,
         }
     } else if (!strcmp(attr, "sprop-parameter-sets")) {
         codec->extradata_size = 0;
-        codec->extradata      = NULL;
+        av_freep(&codec->extradata);
 
         while (*value) {
             char base64packet[1024];
@@ -137,29 +136,28 @@ static int sdp_parse_fmtp_config_h264(AVStream *stream,
                 uint8_t *dest = av_malloc(packet_size + sizeof(start_sequence) +
                                           codec->extradata_size +
                                           FF_INPUT_BUFFER_PADDING_SIZE);
-                if (dest) {
-                    if (codec->extradata_size) {
-                        memcpy(dest, codec->extradata, codec->extradata_size);
-                        av_free(codec->extradata);
-                    }
-
-                    memcpy(dest + codec->extradata_size, start_sequence,
-                           sizeof(start_sequence));
-                    memcpy(dest + codec->extradata_size + sizeof(start_sequence),
-                           decoded_packet, packet_size);
-                    memset(dest + codec->extradata_size + sizeof(start_sequence) +
-                           packet_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
-
-                    codec->extradata       = dest;
-                    codec->extradata_size += sizeof(start_sequence) + packet_size;
-                } else {
+                if (!dest) {
                     av_log(codec, AV_LOG_ERROR,
-                           "Unable to allocate memory for extradata!");
+                           "Unable to allocate memory for extradata!\n");
                     return AVERROR(ENOMEM);
                 }
+                if (codec->extradata_size) {
+                    memcpy(dest, codec->extradata, codec->extradata_size);
+                    av_free(codec->extradata);
+                }
+
+                memcpy(dest + codec->extradata_size, start_sequence,
+                       sizeof(start_sequence));
+                memcpy(dest + codec->extradata_size + sizeof(start_sequence),
+                       decoded_packet, packet_size);
+                memset(dest + codec->extradata_size + sizeof(start_sequence) +
+                       packet_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
+
+                codec->extradata       = dest;
+                codec->extradata_size += sizeof(start_sequence) + packet_size;
             }
         }
-        av_log(codec, AV_LOG_DEBUG, "Extradata set to %p (size: %d)!",
+        av_log(codec, AV_LOG_DEBUG, "Extradata set to %p (size: %d)!\n",
                codec->extradata, codec->extradata_size);
     }
     return 0;
@@ -168,7 +166,8 @@ static int sdp_parse_fmtp_config_h264(AVStream *stream,
 // return 0 on packet, no more left, 1 on packet, 1 on partial packet
 static int h264_handle_packet(AVFormatContext *ctx, PayloadContext *data,
                               AVStream *st, AVPacket *pkt, uint32_t *timestamp,
-                              const uint8_t *buf, int len, int flags)
+                              const uint8_t *buf, int len, uint16_t seq,
+                              int flags)
 {
     uint8_t nal;
     uint8_t type;
@@ -310,7 +309,7 @@ static int h264_handle_packet(AVFormatContext *ctx, PayloadContext *data,
     case 30:                   // undefined
     case 31:                   // undefined
     default:
-        av_log(ctx, AV_LOG_ERROR, "Undefined type (%d)", type);
+        av_log(ctx, AV_LOG_ERROR, "Undefined type (%d)\n", type);
         result = AVERROR_INVALIDDATA;
         break;
     }
@@ -340,6 +339,15 @@ static void h264_free_context(PayloadContext *data)
     av_free(data);
 }
 
+static av_cold int h264_init(AVFormatContext *s, int st_index,
+                             PayloadContext *data)
+{
+    if (st_index < 0)
+        return 0;
+    s->streams[st_index]->need_parsing = AVSTREAM_PARSE_FULL;
+    return 0;
+}
+
 static int parse_h264_sdp_line(AVFormatContext *s, int st_index,
                                PayloadContext *h264_data, const char *line)
 {
@@ -372,7 +380,6 @@ static int parse_h264_sdp_line(AVFormatContext *s, int st_index,
         // set our parameters
         codec->width   = atoi(buf1);
         codec->height  = atoi(p + 1); // skip the -
-        codec->pix_fmt = PIX_FMT_YUV420P;
     } else if (av_strstart(p, "fmtp:", &p)) {
         return ff_parse_fmtp(stream, h264_data, p, sdp_parse_fmtp_config_h264);
     } else if (av_strstart(p, "cliprect:", &p)) {
@@ -385,7 +392,8 @@ static int parse_h264_sdp_line(AVFormatContext *s, int st_index,
 RTPDynamicProtocolHandler ff_h264_dynamic_handler = {
     .enc_name         = "H264",
     .codec_type       = AVMEDIA_TYPE_VIDEO,
-    .codec_id         = CODEC_ID_H264,
+    .codec_id         = AV_CODEC_ID_H264,
+    .init             = h264_init,
     .parse_sdp_a_line = parse_h264_sdp_line,
     .alloc            = h264_new_context,
     .free             = h264_free_context,