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.

719 lines
21KB

  1. /*
  2. *
  3. * This file is part of FFmpeg.
  4. *
  5. * FFmpeg is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2.1 of the License, or (at your option) any later version.
  9. *
  10. * FFmpeg is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with FFmpeg; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. #include "channel_layout.h"
  20. #include "avassert.h"
  21. #include "buffer.h"
  22. #include "common.h"
  23. #include "dict.h"
  24. #include "frame.h"
  25. #include "imgutils.h"
  26. #include "mem.h"
  27. #include "samplefmt.h"
  28. MAKE_ACCESSORS(AVFrame, frame, int64_t, best_effort_timestamp)
  29. MAKE_ACCESSORS(AVFrame, frame, int64_t, pkt_duration)
  30. MAKE_ACCESSORS(AVFrame, frame, int64_t, pkt_pos)
  31. MAKE_ACCESSORS(AVFrame, frame, int64_t, channel_layout)
  32. MAKE_ACCESSORS(AVFrame, frame, int, channels)
  33. MAKE_ACCESSORS(AVFrame, frame, int, sample_rate)
  34. MAKE_ACCESSORS(AVFrame, frame, AVDictionary *, metadata)
  35. MAKE_ACCESSORS(AVFrame, frame, int, decode_error_flags)
  36. MAKE_ACCESSORS(AVFrame, frame, int, pkt_size)
  37. MAKE_ACCESSORS(AVFrame, frame, enum AVColorSpace, colorspace)
  38. MAKE_ACCESSORS(AVFrame, frame, enum AVColorRange, color_range)
  39. #define CHECK_CHANNELS_CONSISTENCY(frame) \
  40. av_assert2(!(frame)->channel_layout || \
  41. (frame)->channels == \
  42. av_get_channel_layout_nb_channels((frame)->channel_layout))
  43. AVDictionary **avpriv_frame_get_metadatap(AVFrame *frame) {return &frame->metadata;};
  44. int av_frame_set_qp_table(AVFrame *f, AVBufferRef *buf, int stride, int qp_type)
  45. {
  46. av_buffer_unref(&f->qp_table_buf);
  47. f->qp_table_buf = buf;
  48. f->qscale_table = buf->data;
  49. f->qstride = stride;
  50. f->qscale_type = qp_type;
  51. return 0;
  52. }
  53. int8_t *av_frame_get_qp_table(AVFrame *f, int *stride, int *type)
  54. {
  55. *stride = f->qstride;
  56. *type = f->qscale_type;
  57. if (!f->qp_table_buf)
  58. return NULL;
  59. return f->qp_table_buf->data;
  60. }
  61. const char *av_get_colorspace_name(enum AVColorSpace val)
  62. {
  63. static const char * const name[] = {
  64. [AVCOL_SPC_RGB] = "GBR",
  65. [AVCOL_SPC_BT709] = "bt709",
  66. [AVCOL_SPC_FCC] = "fcc",
  67. [AVCOL_SPC_BT470BG] = "bt470bg",
  68. [AVCOL_SPC_SMPTE170M] = "smpte170m",
  69. [AVCOL_SPC_SMPTE240M] = "smpte240m",
  70. [AVCOL_SPC_YCOCG] = "YCgCo",
  71. };
  72. if ((unsigned)val >= FF_ARRAY_ELEMS(name))
  73. return NULL;
  74. return name[val];
  75. }
  76. static void get_frame_defaults(AVFrame *frame)
  77. {
  78. if (frame->extended_data != frame->data)
  79. av_freep(&frame->extended_data);
  80. memset(frame, 0, sizeof(*frame));
  81. frame->pts =
  82. frame->pkt_dts =
  83. frame->pkt_pts = AV_NOPTS_VALUE;
  84. av_frame_set_best_effort_timestamp(frame, AV_NOPTS_VALUE);
  85. av_frame_set_pkt_duration (frame, 0);
  86. av_frame_set_pkt_pos (frame, -1);
  87. av_frame_set_pkt_size (frame, -1);
  88. frame->key_frame = 1;
  89. frame->sample_aspect_ratio = (AVRational){ 0, 1 };
  90. frame->format = -1; /* unknown */
  91. frame->extended_data = frame->data;
  92. frame->color_primaries = AVCOL_PRI_UNSPECIFIED;
  93. frame->color_trc = AVCOL_TRC_UNSPECIFIED;
  94. frame->colorspace = AVCOL_SPC_UNSPECIFIED;
  95. frame->color_range = AVCOL_RANGE_UNSPECIFIED;
  96. frame->chroma_location = AVCHROMA_LOC_UNSPECIFIED;
  97. }
  98. static void free_side_data(AVFrameSideData **ptr_sd)
  99. {
  100. AVFrameSideData *sd = *ptr_sd;
  101. av_buffer_unref(&sd->buf);
  102. av_dict_free(&sd->metadata);
  103. av_freep(ptr_sd);
  104. }
  105. static void wipe_side_data(AVFrame *frame)
  106. {
  107. int i;
  108. for (i = 0; i < frame->nb_side_data; i++) {
  109. free_side_data(&frame->side_data[i]);
  110. }
  111. frame->nb_side_data = 0;
  112. av_freep(&frame->side_data);
  113. }
  114. AVFrame *av_frame_alloc(void)
  115. {
  116. AVFrame *frame = av_mallocz(sizeof(*frame));
  117. if (!frame)
  118. return NULL;
  119. frame->extended_data = NULL;
  120. get_frame_defaults(frame);
  121. return frame;
  122. }
  123. void av_frame_free(AVFrame **frame)
  124. {
  125. if (!frame || !*frame)
  126. return;
  127. av_frame_unref(*frame);
  128. av_freep(frame);
  129. }
  130. static int get_video_buffer(AVFrame *frame, int align)
  131. {
  132. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
  133. int ret, i;
  134. if (!desc)
  135. return AVERROR(EINVAL);
  136. if ((ret = av_image_check_size(frame->width, frame->height, 0, NULL)) < 0)
  137. return ret;
  138. if (!frame->linesize[0]) {
  139. for(i=1; i<=align; i+=i) {
  140. ret = av_image_fill_linesizes(frame->linesize, frame->format,
  141. FFALIGN(frame->width, i));
  142. if (ret < 0)
  143. return ret;
  144. if (!(frame->linesize[0] & (align-1)))
  145. break;
  146. }
  147. for (i = 0; i < 4 && frame->linesize[i]; i++)
  148. frame->linesize[i] = FFALIGN(frame->linesize[i], align);
  149. }
  150. for (i = 0; i < 4 && frame->linesize[i]; i++) {
  151. int h = FFALIGN(frame->height, 32);
  152. if (i == 1 || i == 2)
  153. h = FF_CEIL_RSHIFT(h, desc->log2_chroma_h);
  154. frame->buf[i] = av_buffer_alloc(frame->linesize[i] * h + 16 + 16/*STRIDE_ALIGN*/ - 1);
  155. if (!frame->buf[i])
  156. goto fail;
  157. frame->data[i] = frame->buf[i]->data;
  158. }
  159. if (desc->flags & AV_PIX_FMT_FLAG_PAL || desc->flags & AV_PIX_FMT_FLAG_PSEUDOPAL) {
  160. av_buffer_unref(&frame->buf[1]);
  161. frame->buf[1] = av_buffer_alloc(1024);
  162. if (!frame->buf[1])
  163. goto fail;
  164. frame->data[1] = frame->buf[1]->data;
  165. }
  166. frame->extended_data = frame->data;
  167. return 0;
  168. fail:
  169. av_frame_unref(frame);
  170. return AVERROR(ENOMEM);
  171. }
  172. static int get_audio_buffer(AVFrame *frame, int align)
  173. {
  174. int channels;
  175. int planar = av_sample_fmt_is_planar(frame->format);
  176. int planes;
  177. int ret, i;
  178. if (!frame->channels)
  179. frame->channels = av_get_channel_layout_nb_channels(frame->channel_layout);
  180. channels = frame->channels;
  181. planes = planar ? channels : 1;
  182. CHECK_CHANNELS_CONSISTENCY(frame);
  183. if (!frame->linesize[0]) {
  184. ret = av_samples_get_buffer_size(&frame->linesize[0], channels,
  185. frame->nb_samples, frame->format,
  186. align);
  187. if (ret < 0)
  188. return ret;
  189. }
  190. if (planes > AV_NUM_DATA_POINTERS) {
  191. frame->extended_data = av_mallocz_array(planes,
  192. sizeof(*frame->extended_data));
  193. frame->extended_buf = av_mallocz_array((planes - AV_NUM_DATA_POINTERS),
  194. sizeof(*frame->extended_buf));
  195. if (!frame->extended_data || !frame->extended_buf) {
  196. av_freep(&frame->extended_data);
  197. av_freep(&frame->extended_buf);
  198. return AVERROR(ENOMEM);
  199. }
  200. frame->nb_extended_buf = planes - AV_NUM_DATA_POINTERS;
  201. } else
  202. frame->extended_data = frame->data;
  203. for (i = 0; i < FFMIN(planes, AV_NUM_DATA_POINTERS); i++) {
  204. frame->buf[i] = av_buffer_alloc(frame->linesize[0]);
  205. if (!frame->buf[i]) {
  206. av_frame_unref(frame);
  207. return AVERROR(ENOMEM);
  208. }
  209. frame->extended_data[i] = frame->data[i] = frame->buf[i]->data;
  210. }
  211. for (i = 0; i < planes - AV_NUM_DATA_POINTERS; i++) {
  212. frame->extended_buf[i] = av_buffer_alloc(frame->linesize[0]);
  213. if (!frame->extended_buf[i]) {
  214. av_frame_unref(frame);
  215. return AVERROR(ENOMEM);
  216. }
  217. frame->extended_data[i + AV_NUM_DATA_POINTERS] = frame->extended_buf[i]->data;
  218. }
  219. return 0;
  220. }
  221. int av_frame_get_buffer(AVFrame *frame, int align)
  222. {
  223. if (frame->format < 0)
  224. return AVERROR(EINVAL);
  225. if (frame->width > 0 && frame->height > 0)
  226. return get_video_buffer(frame, align);
  227. else if (frame->nb_samples > 0 && (frame->channel_layout || frame->channels > 0))
  228. return get_audio_buffer(frame, align);
  229. return AVERROR(EINVAL);
  230. }
  231. static int frame_copy_props(AVFrame *dst, const AVFrame *src, int force_copy)
  232. {
  233. int i;
  234. dst->key_frame = src->key_frame;
  235. dst->pict_type = src->pict_type;
  236. dst->sample_aspect_ratio = src->sample_aspect_ratio;
  237. dst->pts = src->pts;
  238. dst->repeat_pict = src->repeat_pict;
  239. dst->interlaced_frame = src->interlaced_frame;
  240. dst->top_field_first = src->top_field_first;
  241. dst->palette_has_changed = src->palette_has_changed;
  242. dst->sample_rate = src->sample_rate;
  243. dst->opaque = src->opaque;
  244. #if FF_API_AVFRAME_LAVC
  245. dst->type = src->type;
  246. #endif
  247. dst->pkt_pts = src->pkt_pts;
  248. dst->pkt_dts = src->pkt_dts;
  249. dst->pkt_pos = src->pkt_pos;
  250. dst->pkt_size = src->pkt_size;
  251. dst->pkt_duration = src->pkt_duration;
  252. dst->reordered_opaque = src->reordered_opaque;
  253. dst->quality = src->quality;
  254. dst->best_effort_timestamp = src->best_effort_timestamp;
  255. dst->coded_picture_number = src->coded_picture_number;
  256. dst->display_picture_number = src->display_picture_number;
  257. dst->flags = src->flags;
  258. dst->decode_error_flags = src->decode_error_flags;
  259. dst->color_primaries = src->color_primaries;
  260. dst->color_trc = src->color_trc;
  261. dst->colorspace = src->colorspace;
  262. dst->color_range = src->color_range;
  263. dst->chroma_location = src->chroma_location;
  264. av_dict_copy(&dst->metadata, src->metadata, 0);
  265. memcpy(dst->error, src->error, sizeof(dst->error));
  266. for (i = 0; i < src->nb_side_data; i++) {
  267. const AVFrameSideData *sd_src = src->side_data[i];
  268. AVFrameSideData *sd_dst;
  269. if ( sd_src->type == AV_FRAME_DATA_PANSCAN
  270. && (src->width != dst->width || src->height != dst->height))
  271. continue;
  272. if (force_copy) {
  273. sd_dst = av_frame_new_side_data(dst, sd_src->type,
  274. sd_src->size);
  275. if (!sd_dst) {
  276. wipe_side_data(dst);
  277. return AVERROR(ENOMEM);
  278. }
  279. memcpy(sd_dst->data, sd_src->data, sd_src->size);
  280. } else {
  281. sd_dst = av_frame_new_side_data(dst, sd_src->type, 0);
  282. if (!sd_dst) {
  283. wipe_side_data(dst);
  284. return AVERROR(ENOMEM);
  285. }
  286. sd_dst->buf = av_buffer_ref(sd_src->buf);
  287. if (!sd_dst->buf) {
  288. wipe_side_data(dst);
  289. return AVERROR(ENOMEM);
  290. }
  291. sd_dst->data = sd_dst->buf->data;
  292. sd_dst->size = sd_dst->buf->size;
  293. }
  294. av_dict_copy(&sd_dst->metadata, sd_src->metadata, 0);
  295. }
  296. dst->qscale_table = NULL;
  297. dst->qstride = 0;
  298. dst->qscale_type = 0;
  299. if (src->qp_table_buf) {
  300. dst->qp_table_buf = av_buffer_ref(src->qp_table_buf);
  301. if (dst->qp_table_buf) {
  302. dst->qscale_table = dst->qp_table_buf->data;
  303. dst->qstride = src->qstride;
  304. dst->qscale_type = src->qscale_type;
  305. }
  306. }
  307. return 0;
  308. }
  309. int av_frame_ref(AVFrame *dst, const AVFrame *src)
  310. {
  311. int i, ret = 0;
  312. dst->format = src->format;
  313. dst->width = src->width;
  314. dst->height = src->height;
  315. dst->channels = src->channels;
  316. dst->channel_layout = src->channel_layout;
  317. dst->nb_samples = src->nb_samples;
  318. ret = frame_copy_props(dst, src, 0);
  319. if (ret < 0)
  320. return ret;
  321. /* duplicate the frame data if it's not refcounted */
  322. if (!src->buf[0]) {
  323. ret = av_frame_get_buffer(dst, 32);
  324. if (ret < 0)
  325. return ret;
  326. ret = av_frame_copy(dst, src);
  327. if (ret < 0)
  328. av_frame_unref(dst);
  329. return ret;
  330. }
  331. /* ref the buffers */
  332. for (i = 0; i < FF_ARRAY_ELEMS(src->buf); i++) {
  333. if (!src->buf[i])
  334. continue;
  335. dst->buf[i] = av_buffer_ref(src->buf[i]);
  336. if (!dst->buf[i]) {
  337. ret = AVERROR(ENOMEM);
  338. goto fail;
  339. }
  340. }
  341. if (src->extended_buf) {
  342. dst->extended_buf = av_mallocz_array(sizeof(*dst->extended_buf),
  343. src->nb_extended_buf);
  344. if (!dst->extended_buf) {
  345. ret = AVERROR(ENOMEM);
  346. goto fail;
  347. }
  348. dst->nb_extended_buf = src->nb_extended_buf;
  349. for (i = 0; i < src->nb_extended_buf; i++) {
  350. dst->extended_buf[i] = av_buffer_ref(src->extended_buf[i]);
  351. if (!dst->extended_buf[i]) {
  352. ret = AVERROR(ENOMEM);
  353. goto fail;
  354. }
  355. }
  356. }
  357. /* duplicate extended data */
  358. if (src->extended_data != src->data) {
  359. int ch = src->channels;
  360. if (!ch) {
  361. ret = AVERROR(EINVAL);
  362. goto fail;
  363. }
  364. CHECK_CHANNELS_CONSISTENCY(src);
  365. dst->extended_data = av_malloc_array(sizeof(*dst->extended_data), ch);
  366. if (!dst->extended_data) {
  367. ret = AVERROR(ENOMEM);
  368. goto fail;
  369. }
  370. memcpy(dst->extended_data, src->extended_data, sizeof(*src->extended_data) * ch);
  371. } else
  372. dst->extended_data = dst->data;
  373. memcpy(dst->data, src->data, sizeof(src->data));
  374. memcpy(dst->linesize, src->linesize, sizeof(src->linesize));
  375. return 0;
  376. fail:
  377. av_frame_unref(dst);
  378. return ret;
  379. }
  380. AVFrame *av_frame_clone(const AVFrame *src)
  381. {
  382. AVFrame *ret = av_frame_alloc();
  383. if (!ret)
  384. return NULL;
  385. if (av_frame_ref(ret, src) < 0)
  386. av_frame_free(&ret);
  387. return ret;
  388. }
  389. void av_frame_unref(AVFrame *frame)
  390. {
  391. int i;
  392. wipe_side_data(frame);
  393. for (i = 0; i < FF_ARRAY_ELEMS(frame->buf); i++)
  394. av_buffer_unref(&frame->buf[i]);
  395. for (i = 0; i < frame->nb_extended_buf; i++)
  396. av_buffer_unref(&frame->extended_buf[i]);
  397. av_freep(&frame->extended_buf);
  398. av_dict_free(&frame->metadata);
  399. av_buffer_unref(&frame->qp_table_buf);
  400. get_frame_defaults(frame);
  401. }
  402. void av_frame_move_ref(AVFrame *dst, AVFrame *src)
  403. {
  404. *dst = *src;
  405. if (src->extended_data == src->data)
  406. dst->extended_data = dst->data;
  407. memset(src, 0, sizeof(*src));
  408. get_frame_defaults(src);
  409. }
  410. int av_frame_is_writable(AVFrame *frame)
  411. {
  412. int i, ret = 1;
  413. /* assume non-refcounted frames are not writable */
  414. if (!frame->buf[0])
  415. return 0;
  416. for (i = 0; i < FF_ARRAY_ELEMS(frame->buf); i++)
  417. if (frame->buf[i])
  418. ret &= !!av_buffer_is_writable(frame->buf[i]);
  419. for (i = 0; i < frame->nb_extended_buf; i++)
  420. ret &= !!av_buffer_is_writable(frame->extended_buf[i]);
  421. return ret;
  422. }
  423. int av_frame_make_writable(AVFrame *frame)
  424. {
  425. AVFrame tmp;
  426. int ret;
  427. if (!frame->buf[0])
  428. return AVERROR(EINVAL);
  429. if (av_frame_is_writable(frame))
  430. return 0;
  431. memset(&tmp, 0, sizeof(tmp));
  432. tmp.format = frame->format;
  433. tmp.width = frame->width;
  434. tmp.height = frame->height;
  435. tmp.channels = frame->channels;
  436. tmp.channel_layout = frame->channel_layout;
  437. tmp.nb_samples = frame->nb_samples;
  438. ret = av_frame_get_buffer(&tmp, 32);
  439. if (ret < 0)
  440. return ret;
  441. ret = av_frame_copy(&tmp, frame);
  442. if (ret < 0) {
  443. av_frame_unref(&tmp);
  444. return ret;
  445. }
  446. ret = av_frame_copy_props(&tmp, frame);
  447. if (ret < 0) {
  448. av_frame_unref(&tmp);
  449. return ret;
  450. }
  451. av_frame_unref(frame);
  452. *frame = tmp;
  453. if (tmp.data == tmp.extended_data)
  454. frame->extended_data = frame->data;
  455. return 0;
  456. }
  457. int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
  458. {
  459. return frame_copy_props(dst, src, 1);
  460. }
  461. AVBufferRef *av_frame_get_plane_buffer(AVFrame *frame, int plane)
  462. {
  463. uint8_t *data;
  464. int planes, i;
  465. if (frame->nb_samples) {
  466. int channels = frame->channels;
  467. if (!channels)
  468. return NULL;
  469. CHECK_CHANNELS_CONSISTENCY(frame);
  470. planes = av_sample_fmt_is_planar(frame->format) ? channels : 1;
  471. } else
  472. planes = 4;
  473. if (plane < 0 || plane >= planes || !frame->extended_data[plane])
  474. return NULL;
  475. data = frame->extended_data[plane];
  476. for (i = 0; i < FF_ARRAY_ELEMS(frame->buf) && frame->buf[i]; i++) {
  477. AVBufferRef *buf = frame->buf[i];
  478. if (data >= buf->data && data < buf->data + buf->size)
  479. return buf;
  480. }
  481. for (i = 0; i < frame->nb_extended_buf; i++) {
  482. AVBufferRef *buf = frame->extended_buf[i];
  483. if (data >= buf->data && data < buf->data + buf->size)
  484. return buf;
  485. }
  486. return NULL;
  487. }
  488. AVFrameSideData *av_frame_new_side_data(AVFrame *frame,
  489. enum AVFrameSideDataType type,
  490. int size)
  491. {
  492. AVFrameSideData *ret, **tmp;
  493. if (frame->nb_side_data > INT_MAX / sizeof(*frame->side_data) - 1)
  494. return NULL;
  495. tmp = av_realloc(frame->side_data,
  496. (frame->nb_side_data + 1) * sizeof(*frame->side_data));
  497. if (!tmp)
  498. return NULL;
  499. frame->side_data = tmp;
  500. ret = av_mallocz(sizeof(*ret));
  501. if (!ret)
  502. return NULL;
  503. if (size > 0) {
  504. ret->buf = av_buffer_alloc(size);
  505. if (!ret->buf) {
  506. av_freep(&ret);
  507. return NULL;
  508. }
  509. ret->data = ret->buf->data;
  510. ret->size = size;
  511. }
  512. ret->type = type;
  513. frame->side_data[frame->nb_side_data++] = ret;
  514. return ret;
  515. }
  516. AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,
  517. enum AVFrameSideDataType type)
  518. {
  519. int i;
  520. for (i = 0; i < frame->nb_side_data; i++) {
  521. if (frame->side_data[i]->type == type)
  522. return frame->side_data[i];
  523. }
  524. return NULL;
  525. }
  526. static int frame_copy_video(AVFrame *dst, const AVFrame *src)
  527. {
  528. const uint8_t *src_data[4];
  529. int i, planes;
  530. if (dst->width < src->width ||
  531. dst->height < src->height)
  532. return AVERROR(EINVAL);
  533. planes = av_pix_fmt_count_planes(dst->format);
  534. for (i = 0; i < planes; i++)
  535. if (!dst->data[i] || !src->data[i])
  536. return AVERROR(EINVAL);
  537. memcpy(src_data, src->data, sizeof(src_data));
  538. av_image_copy(dst->data, dst->linesize,
  539. src_data, src->linesize,
  540. dst->format, src->width, src->height);
  541. return 0;
  542. }
  543. static int frame_copy_audio(AVFrame *dst, const AVFrame *src)
  544. {
  545. int planar = av_sample_fmt_is_planar(dst->format);
  546. int channels = dst->channels;
  547. int planes = planar ? channels : 1;
  548. int i;
  549. if (dst->nb_samples != src->nb_samples ||
  550. dst->channels != src->channels ||
  551. dst->channel_layout != src->channel_layout)
  552. return AVERROR(EINVAL);
  553. CHECK_CHANNELS_CONSISTENCY(src);
  554. for (i = 0; i < planes; i++)
  555. if (!dst->extended_data[i] || !src->extended_data[i])
  556. return AVERROR(EINVAL);
  557. av_samples_copy(dst->extended_data, src->extended_data, 0, 0,
  558. dst->nb_samples, channels, dst->format);
  559. return 0;
  560. }
  561. int av_frame_copy(AVFrame *dst, const AVFrame *src)
  562. {
  563. if (dst->format != src->format || dst->format < 0)
  564. return AVERROR(EINVAL);
  565. if (dst->width > 0 && dst->height > 0)
  566. return frame_copy_video(dst, src);
  567. else if (dst->nb_samples > 0 && dst->channel_layout)
  568. return frame_copy_audio(dst, src);
  569. return AVERROR(EINVAL);
  570. }
  571. void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type)
  572. {
  573. int i;
  574. for (i = 0; i < frame->nb_side_data; i++) {
  575. AVFrameSideData *sd = frame->side_data[i];
  576. if (sd->type == type) {
  577. free_side_data(&frame->side_data[i]);
  578. frame->side_data[i] = frame->side_data[frame->nb_side_data - 1];
  579. frame->nb_side_data--;
  580. }
  581. }
  582. }
  583. const char *av_frame_side_data_name(enum AVFrameSideDataType type)
  584. {
  585. switch(type) {
  586. case AV_FRAME_DATA_PANSCAN: return "AVPanScan";
  587. case AV_FRAME_DATA_A53_CC: return "ATSC A53 Part 4 Closed Captions";
  588. case AV_FRAME_DATA_STEREO3D: return "Stereoscopic 3d metadata";
  589. case AV_FRAME_DATA_MATRIXENCODING: return "AVMatrixEncoding";
  590. case AV_FRAME_DATA_DOWNMIX_INFO: return "Metadata relevant to a downmix procedure";
  591. case AV_FRAME_DATA_REPLAYGAIN: return "AVReplayGain";
  592. case AV_FRAME_DATA_DISPLAYMATRIX: return "3x3 displaymatrix";
  593. case AV_FRAME_DATA_MOTION_VECTORS: return "Motion vectors";
  594. }
  595. return NULL;
  596. }