]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/rtpdec_hevc.c
rtpdec_vp9: Update header parsing to spec draft 02
[ffmpeg] / libavformat / rtpdec_hevc.c
index e04725be5d8ee83539790957f84ca25b7775de78..97f87aeec353ef126e0c7375fd48b422a8f5ba96 100644 (file)
@@ -17,7 +17,6 @@
  * You should have received a copy of the GNU Lesser General Public
  * License along with Libav; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
  */
 
 #include "libavutil/avstring.h"
@@ -46,13 +45,13 @@ static const uint8_t start_sequence[] = { 0x00, 0x00, 0x00, 0x01 };
 static av_cold int hevc_sdp_parse_fmtp_config(AVFormatContext *s,
                                               AVStream *stream,
                                               PayloadContext *hevc_data,
-                                              char *attr, char *value)
+                                              const char *attr, const char *value)
 {
     /* profile-space: 0-3 */
     /* profile-id: 0-31 */
     if (!strcmp(attr, "profile-id")) {
         hevc_data->profile_id = atoi(value);
-        av_dlog(s, "SDP: found profile-id: %d\n", hevc_data->profile_id);
+        av_log(s, AV_LOG_TRACE, "SDP: found profile-id: %d\n", hevc_data->profile_id);
     }
 
     /* tier-flag: 0-1 */
@@ -102,7 +101,7 @@ static av_cold int hevc_sdp_parse_fmtp_config(AVFormatContext *s,
     if (!strcmp(attr, "sprop-max-don-diff")) {
         if (atoi(value) > 0)
             hevc_data->using_donl_field = 1;
-        av_dlog(s, "Found sprop-max-don-diff in SDP, DON field usage is: %d\n",
+        av_log(s, AV_LOG_TRACE, "Found sprop-max-don-diff in SDP, DON field usage is: %d\n",
                 hevc_data->using_donl_field);
     }
 
@@ -110,7 +109,7 @@ static av_cold int hevc_sdp_parse_fmtp_config(AVFormatContext *s,
     if (!strcmp(attr, "sprop-depack-buf-nalus")) {
         if (atoi(value) > 0)
             hevc_data->using_donl_field = 1;
-        av_dlog(s, "Found sprop-depack-buf-nalus in SDP, DON field usage is: %d\n",
+        av_log(s, AV_LOG_TRACE, "Found sprop-depack-buf-nalus in SDP, DON field usage is: %d\n",
                 hevc_data->using_donl_field);
     }
 
@@ -128,41 +127,41 @@ static av_cold int hevc_parse_sdp_line(AVFormatContext *ctx, int st_index,
                                        PayloadContext *hevc_data, const char *line)
 {
     AVStream *current_stream;
-    AVCodecContext *codec;
+    AVCodecParameters *par;
     const char *sdp_line_ptr = line;
 
     if (st_index < 0)
         return 0;
 
     current_stream = ctx->streams[st_index];
-    codec  = current_stream->codec;
+    par  = current_stream->codecpar;
 
     if (av_strstart(sdp_line_ptr, "framesize:", &sdp_line_ptr)) {
-        ff_h264_parse_framesize(codec, sdp_line_ptr);
+        ff_h264_parse_framesize(par, sdp_line_ptr);
     } else if (av_strstart(sdp_line_ptr, "fmtp:", &sdp_line_ptr)) {
         int ret = ff_parse_fmtp(ctx, current_stream, hevc_data, sdp_line_ptr,
                                 hevc_sdp_parse_fmtp_config);
         if (hevc_data->vps_size || hevc_data->sps_size ||
             hevc_data->pps_size || hevc_data->sei_size) {
-            av_freep(&codec->extradata);
-            codec->extradata_size = hevc_data->vps_size + hevc_data->sps_size +
-                                    hevc_data->pps_size + hevc_data->sei_size;
-            codec->extradata = av_malloc(codec->extradata_size +
-                                         FF_INPUT_BUFFER_PADDING_SIZE);
-            if (!codec->extradata) {
+            av_freep(&par->extradata);
+            par->extradata_size = hevc_data->vps_size + hevc_data->sps_size +
+                                  hevc_data->pps_size + hevc_data->sei_size;
+            par->extradata = av_malloc(par->extradata_size +
+                                       AV_INPUT_BUFFER_PADDING_SIZE);
+            if (!par->extradata) {
                 ret = AVERROR(ENOMEM);
-                codec->extradata_size = 0;
+                par->extradata_size = 0;
             } else {
                 int pos = 0;
-                memcpy(codec->extradata + pos, hevc_data->vps, hevc_data->vps_size);
+                memcpy(par->extradata + pos, hevc_data->vps, hevc_data->vps_size);
                 pos += hevc_data->vps_size;
-                memcpy(codec->extradata + pos, hevc_data->sps, hevc_data->sps_size);
+                memcpy(par->extradata + pos, hevc_data->sps, hevc_data->sps_size);
                 pos += hevc_data->sps_size;
-                memcpy(codec->extradata + pos, hevc_data->pps, hevc_data->pps_size);
+                memcpy(par->extradata + pos, hevc_data->pps, hevc_data->pps_size);
                 pos += hevc_data->pps_size;
-                memcpy(codec->extradata + pos, hevc_data->sei, hevc_data->sei_size);
+                memcpy(par->extradata + pos, hevc_data->sei, hevc_data->sei_size);
                 pos += hevc_data->sei_size;
-                memset(codec->extradata + pos, 0, FF_INPUT_BUFFER_PADDING_SIZE);
+                memset(par->extradata + pos, 0, AV_INPUT_BUFFER_PADDING_SIZE);
             }
 
             av_freep(&hevc_data->vps);
@@ -218,7 +217,7 @@ static int hevc_handle_packet(AVFormatContext *ctx, PayloadContext *rtp_hevc_ctx
     /* sanity check for correct layer ID */
     if (lid) {
         /* future scalable or 3D video coding extensions */
-        avpriv_report_missing_feature(ctx, "Multi-layer HEVC coding\n");
+        avpriv_report_missing_feature(ctx, "Multi-layer HEVC coding");
         return AVERROR_PATCHWELCOME;
     }
 
@@ -245,14 +244,6 @@ static int hevc_handle_packet(AVFormatContext *ctx, PayloadContext *rtp_hevc_ctx
     case 39:
     /* single NAL unit packet */
     default:
-        /* sanity check for size of input packet: 1 byte payload at least */
-        if (len < 1) {
-            av_log(ctx, AV_LOG_ERROR,
-                   "Too short RTP/HEVC packet, got %d bytes of NAL unit type %d\n",
-                   len, nal_type);
-            return AVERROR_INVALIDDATA;
-        }
-
         /* create A/V packet */
         if ((res = av_new_packet(pkt, sizeof(start_sequence) + len)) < 0)
             return res;
@@ -313,7 +304,7 @@ static int hevc_handle_packet(AVFormatContext *ctx, PayloadContext *rtp_hevc_ctx
             len -= RTP_HEVC_DONL_FIELD_SIZE;
         }
 
-        av_dlog(ctx, " FU type %d with %d bytes\n", fu_type, len);
+        av_log(ctx, AV_LOG_TRACE, " FU type %d with %d bytes\n", fu_type, len);
 
         if (len <= 0) {
             /* sanity check for size of input packet: 1 byte payload at least */
@@ -331,30 +322,14 @@ static int hevc_handle_packet(AVFormatContext *ctx, PayloadContext *rtp_hevc_ctx
         new_nal_header[0] = (rtp_pl[0] & 0x81) | (fu_type << 1);
         new_nal_header[1] = rtp_pl[1];
 
-        /* start fragment vs. subsequent fragments */
-        if (first_fragment) {
-            /* create A/V packet which is big enough */
-            if ((res = av_new_packet(pkt, sizeof(start_sequence) + sizeof(new_nal_header) + len)) < 0)
-                return res;
-            /* A/V packet: copy start sequence */
-            memcpy(pkt->data, start_sequence, sizeof(start_sequence));
-            /* A/V packet: copy new NAL header */
-            memcpy(pkt->data + sizeof(start_sequence), new_nal_header, sizeof(new_nal_header));
-            /* A/V packet: copy NAL unit data */
-            memcpy(pkt->data + sizeof(start_sequence) + sizeof(new_nal_header), buf, len);
-        } else {
-            /* create A/V packet */
-            if ((res = av_new_packet(pkt, len)) < 0)
-                return res;
-            /* A/V packet: copy NAL unit data */
-            memcpy(pkt->data, buf, len);
-        }
+        res = ff_h264_handle_frag_packet(pkt, buf, len, first_fragment,
+                                         new_nal_header, sizeof(new_nal_header));
 
         break;
     /* PACI packet */
     case 50:
         /* Temporal scalability control information (TSCI) */
-        avpriv_report_missing_feature(ctx, "PACI packets for RTP/HEVC\n");
+        avpriv_report_missing_feature(ctx, "PACI packets for RTP/HEVC");
         res = AVERROR_PATCHWELCOME;
         break;
     }