]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/rtpdec_h264.c
libavformat: Add a muxer wrapping mpegts encoding into RTP
[ffmpeg] / libavformat / rtpdec_h264.c
index 5e0169bab3316f6652a63e006f6cf823b0989e3c..abf1f39279690b0d7e1f376c5af3ae3287c9686c 100644 (file)
@@ -64,7 +64,8 @@ struct PayloadContext {
 
 static const uint8_t start_sequence[] = { 0, 0, 0, 1 };
 
-static int sdp_parse_fmtp_config_h264(AVStream *stream,
+static int sdp_parse_fmtp_config_h264(AVFormatContext *s,
+                                      AVStream *stream,
                                       PayloadContext *h264_data,
                                       char *attr, char *value)
 {
@@ -73,7 +74,7 @@ static int sdp_parse_fmtp_config_h264(AVStream *stream,
     assert(h264_data != NULL);
 
     if (!strcmp(attr, "packetization-mode")) {
-        av_log(codec, AV_LOG_DEBUG, "RTP Packetization Mode: %d\n", atoi(value));
+        av_log(s, AV_LOG_DEBUG, "RTP Packetization Mode: %d\n", atoi(value));
         h264_data->packetization_mode = atoi(value);
         /*
          * Packetization Mode:
@@ -83,7 +84,7 @@ static int sdp_parse_fmtp_config_h264(AVStream *stream,
          *                      and 29 (FU-B) are allowed.
          */
         if (h264_data->packetization_mode > 1)
-            av_log(codec, AV_LOG_ERROR,
+            av_log(s, AV_LOG_ERROR,
                    "Interleaved RTP mode is not supported yet.\n");
     } else if (!strcmp(attr, "profile-level-id")) {
         if (strlen(value) == 6) {
@@ -104,7 +105,7 @@ static int sdp_parse_fmtp_config_h264(AVStream *stream,
             buffer[1]   = value[5];
             level_idc   = strtol(buffer, NULL, 16);
 
-            av_log(codec, AV_LOG_DEBUG,
+            av_log(s, 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;
@@ -137,7 +138,7 @@ static int sdp_parse_fmtp_config_h264(AVStream *stream,
                                           codec->extradata_size +
                                           FF_INPUT_BUFFER_PADDING_SIZE);
                 if (!dest) {
-                    av_log(codec, AV_LOG_ERROR,
+                    av_log(s, AV_LOG_ERROR,
                            "Unable to allocate memory for extradata!\n");
                     return AVERROR(ENOMEM);
                 }
@@ -157,7 +158,7 @@ static int sdp_parse_fmtp_config_h264(AVStream *stream,
                 codec->extradata_size += sizeof(start_sequence) + packet_size;
             }
         }
-        av_log(codec, AV_LOG_DEBUG, "Extradata set to %p (size: %d)!\n",
+        av_log(s, AV_LOG_DEBUG, "Extradata set to %p (size: %d)!\n",
                codec->extradata, codec->extradata_size);
     }
     return 0;
@@ -190,7 +191,8 @@ static int h264_handle_packet(AVFormatContext *ctx, PayloadContext *data,
     switch (type) {
     case 0:                    // undefined, but pass them through
     case 1:
-        av_new_packet(pkt, len + sizeof(start_sequence));
+        if ((result = av_new_packet(pkt, len + sizeof(start_sequence))) < 0)
+            return result;
         memcpy(pkt->data, start_sequence, sizeof(start_sequence));
         memcpy(pkt->data + sizeof(start_sequence), buf, len);
         COUNT_NAL_TYPE(data, nal);
@@ -247,7 +249,8 @@ static int h264_handle_packet(AVFormatContext *ctx, PayloadContext *data,
                 if (pass == 0) {
                     /* now we know the total size of the packet (with the
                      * start sequences added) */
-                    av_new_packet(pkt, total_length);
+                    if ((result = av_new_packet(pkt, total_length)) < 0)
+                        return result;
                     dst = pkt->data;
                 } else {
                     assert(dst - pkt->data == total_length);
@@ -292,12 +295,14 @@ static int h264_handle_packet(AVFormatContext *ctx, PayloadContext *data,
                 COUNT_NAL_TYPE(data, nal_type);
             if (start_bit) {
                 /* copy in the start sequence, and the reconstructed nal */
-                av_new_packet(pkt, sizeof(start_sequence) + sizeof(nal) + len);
+                if ((result = av_new_packet(pkt, sizeof(start_sequence) + sizeof(nal) + len)) < 0)
+                    return result;
                 memcpy(pkt->data, start_sequence, sizeof(start_sequence));
                 pkt->data[sizeof(start_sequence)] = reconstructed_nal;
                 memcpy(pkt->data + sizeof(start_sequence) + sizeof(nal), buf, len);
             } else {
-                av_new_packet(pkt, len);
+                if ((result = av_new_packet(pkt, len)) < 0)
+                    return result;
                 memcpy(pkt->data, buf, len);
             }
         } else {
@@ -381,7 +386,7 @@ static int parse_h264_sdp_line(AVFormatContext *s, int st_index,
         codec->width   = atoi(buf1);
         codec->height  = atoi(p + 1); // skip the -
     } else if (av_strstart(p, "fmtp:", &p)) {
-        return ff_parse_fmtp(stream, h264_data, p, sdp_parse_fmtp_config_h264);
+        return ff_parse_fmtp(s, stream, h264_data, p, sdp_parse_fmtp_config_h264);
     } else if (av_strstart(p, "cliprect:", &p)) {
         // could use this if we wanted.
     }