Browse code

lavf: simplify ff_hevc_annexb2mp4_buf

Use ff_hevc_annexb2mp4 instead of duplicating
its functionality, and update the documentation
to match the new behavior.

(cherry picked from commit 34bbc81de8a49fbddb92b76dc733f40890480b2b)

Tim Walker authored on 2014/03/11 00:03:13
Showing 2 changed files
... ...
@@ -1066,52 +1066,15 @@ int ff_hevc_annexb2mp4_buf(const uint8_t *buf_in, uint8_t **buf_out,
1066 1066
                            int *size, int filter_ps, int *ps_count)
1067 1067
 {
1068 1068
     AVIOContext *pb;
1069
-    int num_ps = 0, ret = 0;
1070
-    uint8_t *buf, *end, *start = NULL;
1071
-
1072
-    if (!filter_ps) {
1073
-        ret = ff_avc_parse_nal_units_buf(buf_in, buf_out, size);
1074
-        goto end;
1075
-    }
1069
+    int ret;
1076 1070
 
1077 1071
     ret = avio_open_dyn_buf(&pb);
1078 1072
     if (ret < 0)
1079
-        goto end;
1080
-
1081
-    ret = ff_avc_parse_nal_units_buf(buf_in, &start, size);
1082
-    if (ret < 0)
1083
-        goto end;
1084
-
1085
-    buf = start;
1086
-    end = start + *size;
1087
-
1088
-    while (end - buf > 4) {
1089
-        uint32_t len = FFMIN(AV_RB32(buf), end - buf - 4);
1090
-        uint8_t type = (buf[4] >> 1) & 0x3f;
1091
-
1092
-        buf += 4;
1093
-
1094
-        switch (type) {
1095
-        case NAL_VPS:
1096
-        case NAL_SPS:
1097
-        case NAL_PPS:
1098
-            num_ps++;
1099
-            break;
1100
-        default:
1101
-            avio_wb32(pb, len);
1102
-            avio_write(pb, buf, len);
1103
-            break;
1104
-        }
1105
-
1106
-        buf += len;
1107
-    }
1073
+        return ret;
1108 1074
 
1075
+    ret   = ff_hevc_annexb2mp4(pb, buf_in, *size, filter_ps, ps_count);
1109 1076
     *size = avio_close_dyn_buf(pb, buf_out);
1110 1077
 
1111
-end:
1112
-    free(start);
1113
-    if (ps_count)
1114
-        *ps_count = num_ps;
1115 1078
     return ret;
1116 1079
 }
1117 1080
 
... ...
@@ -71,8 +71,8 @@ int ff_hevc_annexb2mp4(AVIOContext *pb, const uint8_t *buf_in,
71 71
  *        or to discard them (non-zero)
72 72
  * @param ps_count address of the variable where the number of discarded
73 73
  *        parameter set NAL units shall be written, may be NULL
74
- * @return 0 in case of success, a negative value corresponding to an AVERROR
75
- *         code in case of failure
74
+ * @return the amount (in bytes) of data written in case of success, a negative
75
+ *         value corresponding to an AVERROR code in case of failure
76 76
  */
77 77
 int ff_hevc_annexb2mp4_buf(const uint8_t *buf_in, uint8_t **buf_out,
78 78
                            int *size, int filter_ps, int *ps_count);