You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

638 lines
22KB

  1. /*
  2. * H.26L/H.264/AVC/JVT/14496-10/... parser
  3. * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file
  23. * H.264 / AVC / MPEG4 part10 parser.
  24. * @author Michael Niedermayer <michaelni@gmx.at>
  25. */
  26. #define UNCHECKED_BITSTREAM_READER 1
  27. #include <assert.h>
  28. #include <stdint.h>
  29. #include "libavutil/avutil.h"
  30. #include "libavutil/error.h"
  31. #include "libavutil/log.h"
  32. #include "libavutil/mem.h"
  33. #include "libavutil/pixfmt.h"
  34. #include "get_bits.h"
  35. #include "golomb.h"
  36. #include "h264.h"
  37. #include "h264data.h"
  38. #include "internal.h"
  39. #include "mpegutils.h"
  40. #include "parser.h"
  41. typedef struct H264ParseContext {
  42. H264Context h;
  43. ParseContext pc;
  44. int got_first;
  45. } H264ParseContext;
  46. static int h264_find_frame_end(H264ParseContext *p, const uint8_t *buf,
  47. int buf_size)
  48. {
  49. H264Context *h = &p->h;
  50. int i, j;
  51. uint32_t state;
  52. ParseContext *pc = &p->pc;
  53. int next_avc= h->is_avc ? 0 : buf_size;
  54. // mb_addr= pc->mb_addr - 1;
  55. state = pc->state;
  56. if (state > 13)
  57. state = 7;
  58. if (h->is_avc && !h->nal_length_size)
  59. av_log(h->avctx, AV_LOG_ERROR, "AVC-parser: nal length size invalid\n");
  60. for (i = 0; i < buf_size; i++) {
  61. if (i >= next_avc) {
  62. int nalsize = 0;
  63. i = next_avc;
  64. for (j = 0; j < h->nal_length_size; j++)
  65. nalsize = (nalsize << 8) | buf[i++];
  66. if (nalsize <= 0 || nalsize > buf_size - i) {
  67. av_log(h->avctx, AV_LOG_ERROR, "AVC-parser: nal size %d remaining %d\n", nalsize, buf_size - i);
  68. return buf_size;
  69. }
  70. next_avc = i + nalsize;
  71. state = 5;
  72. }
  73. if (state == 7) {
  74. i += h->h264dsp.startcode_find_candidate(buf + i, next_avc - i);
  75. if (i < next_avc)
  76. state = 2;
  77. } else if (state <= 2) {
  78. if (buf[i] == 1)
  79. state ^= 5; // 2->7, 1->4, 0->5
  80. else if (buf[i])
  81. state = 7;
  82. else
  83. state >>= 1; // 2->1, 1->0, 0->0
  84. } else if (state <= 5) {
  85. int nalu_type = buf[i] & 0x1F;
  86. if (nalu_type == NAL_SEI || nalu_type == NAL_SPS ||
  87. nalu_type == NAL_PPS || nalu_type == NAL_AUD) {
  88. if (pc->frame_start_found) {
  89. i++;
  90. goto found;
  91. }
  92. } else if (nalu_type == NAL_SLICE || nalu_type == NAL_DPA ||
  93. nalu_type == NAL_IDR_SLICE) {
  94. state += 8;
  95. continue;
  96. }
  97. state = 7;
  98. } else {
  99. h->parse_history[h->parse_history_count++]= buf[i];
  100. if (h->parse_history_count>5) {
  101. unsigned int mb, last_mb= h->parse_last_mb;
  102. GetBitContext gb;
  103. init_get_bits(&gb, h->parse_history, 8*h->parse_history_count);
  104. h->parse_history_count=0;
  105. mb= get_ue_golomb_long(&gb);
  106. h->parse_last_mb= mb;
  107. if (pc->frame_start_found) {
  108. if (mb <= last_mb)
  109. goto found;
  110. } else
  111. pc->frame_start_found = 1;
  112. state = 7;
  113. }
  114. }
  115. }
  116. pc->state = state;
  117. if (h->is_avc)
  118. return next_avc;
  119. return END_NOT_FOUND;
  120. found:
  121. pc->state = 7;
  122. pc->frame_start_found = 0;
  123. if (h->is_avc)
  124. return next_avc;
  125. return i - (state & 5) - 5 * (state > 7);
  126. }
  127. static int scan_mmco_reset(AVCodecParserContext *s)
  128. {
  129. H264ParseContext *p = s->priv_data;
  130. H264Context *h = &p->h;
  131. H264SliceContext *sl = &h->slice_ctx[0];
  132. sl->slice_type_nos = s->pict_type & 3;
  133. if (h->pps.redundant_pic_cnt_present)
  134. get_ue_golomb(&sl->gb); // redundant_pic_count
  135. if (ff_set_ref_count(h, sl) < 0)
  136. return AVERROR_INVALIDDATA;
  137. if (sl->slice_type_nos != AV_PICTURE_TYPE_I) {
  138. int list;
  139. for (list = 0; list < sl->list_count; list++) {
  140. if (get_bits1(&sl->gb)) {
  141. int index;
  142. for (index = 0; ; index++) {
  143. unsigned int reordering_of_pic_nums_idc = get_ue_golomb_31(&sl->gb);
  144. if (reordering_of_pic_nums_idc < 3)
  145. get_ue_golomb_long(&sl->gb);
  146. else if (reordering_of_pic_nums_idc > 3) {
  147. av_log(h->avctx, AV_LOG_ERROR,
  148. "illegal reordering_of_pic_nums_idc %d\n",
  149. reordering_of_pic_nums_idc);
  150. return AVERROR_INVALIDDATA;
  151. } else
  152. break;
  153. if (index >= sl->ref_count[list]) {
  154. av_log(h->avctx, AV_LOG_ERROR,
  155. "reference count %d overflow\n", index);
  156. return AVERROR_INVALIDDATA;
  157. }
  158. }
  159. }
  160. }
  161. }
  162. if ((h->pps.weighted_pred && sl->slice_type_nos == AV_PICTURE_TYPE_P) ||
  163. (h->pps.weighted_bipred_idc == 1 && sl->slice_type_nos == AV_PICTURE_TYPE_B))
  164. ff_pred_weight_table(h, sl);
  165. if (get_bits1(&sl->gb)) { // adaptive_ref_pic_marking_mode_flag
  166. int i;
  167. for (i = 0; i < MAX_MMCO_COUNT; i++) {
  168. MMCOOpcode opcode = get_ue_golomb_31(&sl->gb);
  169. if (opcode > (unsigned) MMCO_LONG) {
  170. av_log(h->avctx, AV_LOG_ERROR,
  171. "illegal memory management control operation %d\n",
  172. opcode);
  173. return AVERROR_INVALIDDATA;
  174. }
  175. if (opcode == MMCO_END)
  176. return 0;
  177. else if (opcode == MMCO_RESET)
  178. return 1;
  179. if (opcode == MMCO_SHORT2UNUSED || opcode == MMCO_SHORT2LONG)
  180. get_ue_golomb_long(&sl->gb); // difference_of_pic_nums_minus1
  181. if (opcode == MMCO_SHORT2LONG || opcode == MMCO_LONG2UNUSED ||
  182. opcode == MMCO_LONG || opcode == MMCO_SET_MAX_LONG)
  183. get_ue_golomb_31(&sl->gb);
  184. }
  185. }
  186. return 0;
  187. }
  188. /**
  189. * Parse NAL units of found picture and decode some basic information.
  190. *
  191. * @param s parser context.
  192. * @param avctx codec context.
  193. * @param buf buffer with field/frame data.
  194. * @param buf_size size of the buffer.
  195. */
  196. static inline int parse_nal_units(AVCodecParserContext *s,
  197. AVCodecContext *avctx,
  198. const uint8_t * const buf, int buf_size)
  199. {
  200. H264ParseContext *p = s->priv_data;
  201. H264Context *h = &p->h;
  202. H264SliceContext *sl = &h->slice_ctx[0];
  203. int buf_index, next_avc;
  204. unsigned int pps_id;
  205. unsigned int slice_type;
  206. int state = -1, got_reset = 0;
  207. const uint8_t *ptr;
  208. int q264 = buf_size >=4 && !memcmp("Q264", buf, 4);
  209. int field_poc[2];
  210. /* set some sane default values */
  211. s->pict_type = AV_PICTURE_TYPE_I;
  212. s->key_frame = 0;
  213. s->picture_structure = AV_PICTURE_STRUCTURE_UNKNOWN;
  214. h->avctx = avctx;
  215. ff_h264_reset_sei(h);
  216. h->sei_fpa.frame_packing_arrangement_cancel_flag = -1;
  217. if (!buf_size)
  218. return 0;
  219. buf_index = 0;
  220. next_avc = h->is_avc ? 0 : buf_size;
  221. for (;;) {
  222. int src_length, dst_length, consumed, nalsize = 0;
  223. if (buf_index >= next_avc) {
  224. nalsize = get_avc_nalsize(h, buf, buf_size, &buf_index);
  225. if (nalsize < 0)
  226. break;
  227. next_avc = buf_index + nalsize;
  228. } else {
  229. buf_index = find_start_code(buf, buf_size, buf_index, next_avc);
  230. if (buf_index >= buf_size)
  231. break;
  232. if (buf_index >= next_avc)
  233. continue;
  234. }
  235. src_length = next_avc - buf_index;
  236. state = buf[buf_index];
  237. switch (state & 0x1f) {
  238. case NAL_SLICE:
  239. case NAL_IDR_SLICE:
  240. // Do not walk the whole buffer just to decode slice header
  241. if ((state & 0x1f) == NAL_IDR_SLICE || ((state >> 5) & 0x3) == 0) {
  242. /* IDR or disposable slice
  243. * No need to decode many bytes because MMCOs shall not be present. */
  244. if (src_length > 60)
  245. src_length = 60;
  246. } else {
  247. /* To decode up to MMCOs */
  248. if (src_length > 1000)
  249. src_length = 1000;
  250. }
  251. break;
  252. }
  253. ptr = ff_h264_decode_nal(h, sl, buf + buf_index, &dst_length,
  254. &consumed, src_length);
  255. if (!ptr || dst_length < 0)
  256. break;
  257. buf_index += consumed;
  258. init_get_bits(&h->gb, ptr, 8 * dst_length);
  259. switch (h->nal_unit_type) {
  260. case NAL_SPS:
  261. ff_h264_decode_seq_parameter_set(h, 0);
  262. break;
  263. case NAL_PPS:
  264. ff_h264_decode_picture_parameter_set(h, h->gb.size_in_bits);
  265. break;
  266. case NAL_SEI:
  267. ff_h264_decode_sei(h);
  268. break;
  269. case NAL_IDR_SLICE:
  270. s->key_frame = 1;
  271. h->prev_frame_num = 0;
  272. h->prev_frame_num_offset = 0;
  273. h->prev_poc_msb =
  274. h->prev_poc_lsb = 0;
  275. /* fall through */
  276. case NAL_SLICE:
  277. init_get_bits(&sl->gb, ptr, 8 * dst_length);
  278. get_ue_golomb_long(&sl->gb); // skip first_mb_in_slice
  279. slice_type = get_ue_golomb_31(&sl->gb);
  280. s->pict_type = ff_h264_golomb_to_pict_type[slice_type % 5];
  281. if (h->sei_recovery_frame_cnt >= 0) {
  282. /* key frame, since recovery_frame_cnt is set */
  283. s->key_frame = 1;
  284. }
  285. pps_id = get_ue_golomb(&sl->gb);
  286. if (pps_id >= MAX_PPS_COUNT) {
  287. av_log(h->avctx, AV_LOG_ERROR,
  288. "pps_id %u out of range\n", pps_id);
  289. return -1;
  290. }
  291. if (!h->pps_buffers[pps_id]) {
  292. av_log(h->avctx, AV_LOG_ERROR,
  293. "non-existing PPS %u referenced\n", pps_id);
  294. return -1;
  295. }
  296. h->pps = *h->pps_buffers[pps_id];
  297. if (!h->sps_buffers[h->pps.sps_id]) {
  298. av_log(h->avctx, AV_LOG_ERROR,
  299. "non-existing SPS %u referenced\n", h->pps.sps_id);
  300. return -1;
  301. }
  302. h->sps = *h->sps_buffers[h->pps.sps_id];
  303. h->frame_num = get_bits(&sl->gb, h->sps.log2_max_frame_num);
  304. if(h->sps.ref_frame_count <= 1 && h->pps.ref_count[0] <= 1 && s->pict_type == AV_PICTURE_TYPE_I)
  305. s->key_frame = 1;
  306. s->coded_width = 16 * h->sps.mb_width;
  307. s->coded_height = 16 * h->sps.mb_height;
  308. s->width = s->coded_width - (h->sps.crop_right + h->sps.crop_left);
  309. s->height = s->coded_height - (h->sps.crop_top + h->sps.crop_bottom);
  310. if (s->width <= 0 || s->height <= 0) {
  311. s->width = s->coded_width;
  312. s->height = s->coded_height;
  313. }
  314. switch (h->sps.bit_depth_luma) {
  315. case 9:
  316. if (CHROMA444(h)) s->format = AV_PIX_FMT_YUV444P9;
  317. else if (CHROMA422(h)) s->format = AV_PIX_FMT_YUV422P9;
  318. else s->format = AV_PIX_FMT_YUV420P9;
  319. break;
  320. case 10:
  321. if (CHROMA444(h)) s->format = AV_PIX_FMT_YUV444P10;
  322. else if (CHROMA422(h)) s->format = AV_PIX_FMT_YUV422P10;
  323. else s->format = AV_PIX_FMT_YUV420P10;
  324. break;
  325. case 8:
  326. if (CHROMA444(h)) s->format = AV_PIX_FMT_YUV444P;
  327. else if (CHROMA422(h)) s->format = AV_PIX_FMT_YUV422P;
  328. else s->format = AV_PIX_FMT_YUV420P;
  329. break;
  330. default:
  331. s->format = AV_PIX_FMT_NONE;
  332. }
  333. avctx->profile = ff_h264_get_profile(&h->sps);
  334. avctx->level = h->sps.level_idc;
  335. if (h->sps.frame_mbs_only_flag) {
  336. h->picture_structure = PICT_FRAME;
  337. } else {
  338. if (get_bits1(&sl->gb)) { // field_pic_flag
  339. h->picture_structure = PICT_TOP_FIELD + get_bits1(&sl->gb); // bottom_field_flag
  340. } else {
  341. h->picture_structure = PICT_FRAME;
  342. }
  343. }
  344. if (h->nal_unit_type == NAL_IDR_SLICE)
  345. get_ue_golomb_long(&sl->gb); /* idr_pic_id */
  346. if (h->sps.poc_type == 0) {
  347. h->poc_lsb = get_bits(&sl->gb, h->sps.log2_max_poc_lsb);
  348. if (h->pps.pic_order_present == 1 &&
  349. h->picture_structure == PICT_FRAME)
  350. h->delta_poc_bottom = get_se_golomb(&sl->gb);
  351. }
  352. if (h->sps.poc_type == 1 &&
  353. !h->sps.delta_pic_order_always_zero_flag) {
  354. h->delta_poc[0] = get_se_golomb(&sl->gb);
  355. if (h->pps.pic_order_present == 1 &&
  356. h->picture_structure == PICT_FRAME)
  357. h->delta_poc[1] = get_se_golomb(&sl->gb);
  358. }
  359. /* Decode POC of this picture.
  360. * The prev_ values needed for decoding POC of the next picture are not set here. */
  361. field_poc[0] = field_poc[1] = INT_MAX;
  362. ff_init_poc(h, field_poc, &s->output_picture_number);
  363. /* Continue parsing to check if MMCO_RESET is present.
  364. * FIXME: MMCO_RESET could appear in non-first slice.
  365. * Maybe, we should parse all undisposable non-IDR slice of this
  366. * picture until encountering MMCO_RESET in a slice of it. */
  367. if (h->nal_ref_idc && h->nal_unit_type != NAL_IDR_SLICE) {
  368. got_reset = scan_mmco_reset(s);
  369. if (got_reset < 0)
  370. return got_reset;
  371. }
  372. /* Set up the prev_ values for decoding POC of the next picture. */
  373. h->prev_frame_num = got_reset ? 0 : h->frame_num;
  374. h->prev_frame_num_offset = got_reset ? 0 : h->frame_num_offset;
  375. if (h->nal_ref_idc != 0) {
  376. if (!got_reset) {
  377. h->prev_poc_msb = h->poc_msb;
  378. h->prev_poc_lsb = h->poc_lsb;
  379. } else {
  380. h->prev_poc_msb = 0;
  381. h->prev_poc_lsb =
  382. h->picture_structure == PICT_BOTTOM_FIELD ? 0 : field_poc[0];
  383. }
  384. }
  385. if (h->sps.pic_struct_present_flag) {
  386. switch (h->sei_pic_struct) {
  387. case SEI_PIC_STRUCT_TOP_FIELD:
  388. case SEI_PIC_STRUCT_BOTTOM_FIELD:
  389. s->repeat_pict = 0;
  390. break;
  391. case SEI_PIC_STRUCT_FRAME:
  392. case SEI_PIC_STRUCT_TOP_BOTTOM:
  393. case SEI_PIC_STRUCT_BOTTOM_TOP:
  394. s->repeat_pict = 1;
  395. break;
  396. case SEI_PIC_STRUCT_TOP_BOTTOM_TOP:
  397. case SEI_PIC_STRUCT_BOTTOM_TOP_BOTTOM:
  398. s->repeat_pict = 2;
  399. break;
  400. case SEI_PIC_STRUCT_FRAME_DOUBLING:
  401. s->repeat_pict = 3;
  402. break;
  403. case SEI_PIC_STRUCT_FRAME_TRIPLING:
  404. s->repeat_pict = 5;
  405. break;
  406. default:
  407. s->repeat_pict = h->picture_structure == PICT_FRAME ? 1 : 0;
  408. break;
  409. }
  410. } else {
  411. s->repeat_pict = h->picture_structure == PICT_FRAME ? 1 : 0;
  412. }
  413. if (h->picture_structure == PICT_FRAME) {
  414. s->picture_structure = AV_PICTURE_STRUCTURE_FRAME;
  415. if (h->sps.pic_struct_present_flag) {
  416. switch (h->sei_pic_struct) {
  417. case SEI_PIC_STRUCT_TOP_BOTTOM:
  418. case SEI_PIC_STRUCT_TOP_BOTTOM_TOP:
  419. s->field_order = AV_FIELD_TT;
  420. break;
  421. case SEI_PIC_STRUCT_BOTTOM_TOP:
  422. case SEI_PIC_STRUCT_BOTTOM_TOP_BOTTOM:
  423. s->field_order = AV_FIELD_BB;
  424. break;
  425. default:
  426. s->field_order = AV_FIELD_PROGRESSIVE;
  427. break;
  428. }
  429. } else {
  430. if (field_poc[0] < field_poc[1])
  431. s->field_order = AV_FIELD_TT;
  432. else if (field_poc[0] > field_poc[1])
  433. s->field_order = AV_FIELD_BB;
  434. else
  435. s->field_order = AV_FIELD_PROGRESSIVE;
  436. }
  437. } else {
  438. if (h->picture_structure == PICT_TOP_FIELD)
  439. s->picture_structure = AV_PICTURE_STRUCTURE_TOP_FIELD;
  440. else
  441. s->picture_structure = AV_PICTURE_STRUCTURE_BOTTOM_FIELD;
  442. s->field_order = AV_FIELD_UNKNOWN;
  443. }
  444. return 0; /* no need to evaluate the rest */
  445. }
  446. }
  447. if (q264)
  448. return 0;
  449. /* didn't find a picture! */
  450. av_log(h->avctx, AV_LOG_ERROR, "missing picture in access unit with size %d\n", buf_size);
  451. return -1;
  452. }
  453. static int h264_parse(AVCodecParserContext *s,
  454. AVCodecContext *avctx,
  455. const uint8_t **poutbuf, int *poutbuf_size,
  456. const uint8_t *buf, int buf_size)
  457. {
  458. H264ParseContext *p = s->priv_data;
  459. H264Context *h = &p->h;
  460. ParseContext *pc = &p->pc;
  461. int next;
  462. if (!p->got_first) {
  463. p->got_first = 1;
  464. if (avctx->extradata_size) {
  465. h->avctx = avctx;
  466. // must be done like in decoder, otherwise opening the parser,
  467. // letting it create extradata and then closing and opening again
  468. // will cause has_b_frames to be always set.
  469. // Note that estimate_timings_from_pts does exactly this.
  470. if (!avctx->has_b_frames)
  471. h->low_delay = 1;
  472. ff_h264_decode_extradata(h, avctx->extradata, avctx->extradata_size);
  473. }
  474. }
  475. if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
  476. next = buf_size;
  477. } else {
  478. next = h264_find_frame_end(p, buf, buf_size);
  479. if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
  480. *poutbuf = NULL;
  481. *poutbuf_size = 0;
  482. return buf_size;
  483. }
  484. if (next < 0 && next != END_NOT_FOUND) {
  485. av_assert1(pc->last_index + next >= 0);
  486. h264_find_frame_end(p, &pc->buffer[pc->last_index + next], -next); // update state
  487. }
  488. }
  489. parse_nal_units(s, avctx, buf, buf_size);
  490. if (avctx->framerate.num)
  491. avctx->time_base = av_inv_q(av_mul_q(avctx->framerate, (AVRational){avctx->ticks_per_frame, 1}));
  492. if (h->sei_cpb_removal_delay >= 0) {
  493. s->dts_sync_point = h->sei_buffering_period_present;
  494. s->dts_ref_dts_delta = h->sei_cpb_removal_delay;
  495. s->pts_dts_delta = h->sei_dpb_output_delay;
  496. } else {
  497. s->dts_sync_point = INT_MIN;
  498. s->dts_ref_dts_delta = INT_MIN;
  499. s->pts_dts_delta = INT_MIN;
  500. }
  501. if (s->flags & PARSER_FLAG_ONCE) {
  502. s->flags &= PARSER_FLAG_COMPLETE_FRAMES;
  503. }
  504. *poutbuf = buf;
  505. *poutbuf_size = buf_size;
  506. return next;
  507. }
  508. static int h264_split(AVCodecContext *avctx,
  509. const uint8_t *buf, int buf_size)
  510. {
  511. uint32_t state = -1;
  512. int has_sps = 0;
  513. int has_pps = 0;
  514. const uint8_t *ptr = buf, *end = buf + buf_size;
  515. int nalu_type;
  516. while (ptr < end) {
  517. ptr = avpriv_find_start_code(ptr, end, &state);
  518. if ((state & 0xFFFFFF00) != 0x100)
  519. break;
  520. nalu_type = state & 0x1F;
  521. if (nalu_type == NAL_SPS) {
  522. has_sps = 1;
  523. } else if (nalu_type == NAL_PPS)
  524. has_pps = 1;
  525. /* else if (nalu_type == 0x01 ||
  526. * nalu_type == 0x02 ||
  527. * nalu_type == 0x05) {
  528. * }
  529. */
  530. else if ((nalu_type != NAL_SEI || has_pps) &&
  531. nalu_type != NAL_AUD && nalu_type != NAL_SPS_EXT &&
  532. nalu_type != 0x0f) {
  533. if (has_sps) {
  534. while (ptr - 4 > buf && ptr[-5] == 0)
  535. ptr--;
  536. return ptr - 4 - buf;
  537. }
  538. }
  539. }
  540. return 0;
  541. }
  542. static void h264_close(AVCodecParserContext *s)
  543. {
  544. H264ParseContext *p = s->priv_data;
  545. H264Context *h = &p->h;
  546. ParseContext *pc = &p->pc;
  547. av_freep(&pc->buffer);
  548. ff_h264_free_context(h);
  549. }
  550. static av_cold int init(AVCodecParserContext *s)
  551. {
  552. H264ParseContext *p = s->priv_data;
  553. H264Context *h = &p->h;
  554. h->slice_ctx = av_mallocz(sizeof(*h->slice_ctx));
  555. if (!h->slice_ctx)
  556. return 0;
  557. h->nb_slice_ctx = 1;
  558. h->slice_context_count = 1;
  559. ff_h264dsp_init(&h->h264dsp, 8, 1);
  560. return 0;
  561. }
  562. AVCodecParser ff_h264_parser = {
  563. .codec_ids = { AV_CODEC_ID_H264 },
  564. .priv_data_size = sizeof(H264ParseContext),
  565. .parser_init = init,
  566. .parser_parse = h264_parse,
  567. .parser_close = h264_close,
  568. .split = h264_split,
  569. };