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.

724 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. FF_DISABLE_DEPRECATION_WARNINGS
  246. dst->type = src->type;
  247. FF_ENABLE_DEPRECATION_WARNINGS
  248. #endif
  249. dst->pkt_pts = src->pkt_pts;
  250. dst->pkt_dts = src->pkt_dts;
  251. dst->pkt_pos = src->pkt_pos;
  252. dst->pkt_size = src->pkt_size;
  253. dst->pkt_duration = src->pkt_duration;
  254. dst->reordered_opaque = src->reordered_opaque;
  255. dst->quality = src->quality;
  256. dst->best_effort_timestamp = src->best_effort_timestamp;
  257. dst->coded_picture_number = src->coded_picture_number;
  258. dst->display_picture_number = src->display_picture_number;
  259. dst->flags = src->flags;
  260. dst->decode_error_flags = src->decode_error_flags;
  261. dst->color_primaries = src->color_primaries;
  262. dst->color_trc = src->color_trc;
  263. dst->colorspace = src->colorspace;
  264. dst->color_range = src->color_range;
  265. dst->chroma_location = src->chroma_location;
  266. av_dict_copy(&dst->metadata, src->metadata, 0);
  267. memcpy(dst->error, src->error, sizeof(dst->error));
  268. for (i = 0; i < src->nb_side_data; i++) {
  269. const AVFrameSideData *sd_src = src->side_data[i];
  270. AVFrameSideData *sd_dst;
  271. if ( sd_src->type == AV_FRAME_DATA_PANSCAN
  272. && (src->width != dst->width || src->height != dst->height))
  273. continue;
  274. if (force_copy) {
  275. sd_dst = av_frame_new_side_data(dst, sd_src->type,
  276. sd_src->size);
  277. if (!sd_dst) {
  278. wipe_side_data(dst);
  279. return AVERROR(ENOMEM);
  280. }
  281. memcpy(sd_dst->data, sd_src->data, sd_src->size);
  282. } else {
  283. sd_dst = av_frame_new_side_data(dst, sd_src->type, 0);
  284. if (!sd_dst) {
  285. wipe_side_data(dst);
  286. return AVERROR(ENOMEM);
  287. }
  288. sd_dst->buf = av_buffer_ref(sd_src->buf);
  289. if (!sd_dst->buf) {
  290. wipe_side_data(dst);
  291. return AVERROR(ENOMEM);
  292. }
  293. sd_dst->data = sd_dst->buf->data;
  294. sd_dst->size = sd_dst->buf->size;
  295. }
  296. av_dict_copy(&sd_dst->metadata, sd_src->metadata, 0);
  297. }
  298. dst->qscale_table = NULL;
  299. dst->qstride = 0;
  300. dst->qscale_type = 0;
  301. if (src->qp_table_buf) {
  302. dst->qp_table_buf = av_buffer_ref(src->qp_table_buf);
  303. if (dst->qp_table_buf) {
  304. dst->qscale_table = dst->qp_table_buf->data;
  305. dst->qstride = src->qstride;
  306. dst->qscale_type = src->qscale_type;
  307. }
  308. }
  309. return 0;
  310. }
  311. int av_frame_ref(AVFrame *dst, const AVFrame *src)
  312. {
  313. int i, ret = 0;
  314. dst->format = src->format;
  315. dst->width = src->width;
  316. dst->height = src->height;
  317. dst->channels = src->channels;
  318. dst->channel_layout = src->channel_layout;
  319. dst->nb_samples = src->nb_samples;
  320. ret = frame_copy_props(dst, src, 0);
  321. if (ret < 0)
  322. return ret;
  323. /* duplicate the frame data if it's not refcounted */
  324. if (!src->buf[0]) {
  325. ret = av_frame_get_buffer(dst, 32);
  326. if (ret < 0)
  327. return ret;
  328. ret = av_frame_copy(dst, src);
  329. if (ret < 0)
  330. av_frame_unref(dst);
  331. return ret;
  332. }
  333. /* ref the buffers */
  334. for (i = 0; i < FF_ARRAY_ELEMS(src->buf); i++) {
  335. if (!src->buf[i])
  336. continue;
  337. dst->buf[i] = av_buffer_ref(src->buf[i]);
  338. if (!dst->buf[i]) {
  339. ret = AVERROR(ENOMEM);
  340. goto fail;
  341. }
  342. }
  343. if (src->extended_buf) {
  344. dst->extended_buf = av_mallocz_array(sizeof(*dst->extended_buf),
  345. src->nb_extended_buf);
  346. if (!dst->extended_buf) {
  347. ret = AVERROR(ENOMEM);
  348. goto fail;
  349. }
  350. dst->nb_extended_buf = src->nb_extended_buf;
  351. for (i = 0; i < src->nb_extended_buf; i++) {
  352. dst->extended_buf[i] = av_buffer_ref(src->extended_buf[i]);
  353. if (!dst->extended_buf[i]) {
  354. ret = AVERROR(ENOMEM);
  355. goto fail;
  356. }
  357. }
  358. }
  359. /* duplicate extended data */
  360. if (src->extended_data != src->data) {
  361. int ch = src->channels;
  362. if (!ch) {
  363. ret = AVERROR(EINVAL);
  364. goto fail;
  365. }
  366. CHECK_CHANNELS_CONSISTENCY(src);
  367. dst->extended_data = av_malloc_array(sizeof(*dst->extended_data), ch);
  368. if (!dst->extended_data) {
  369. ret = AVERROR(ENOMEM);
  370. goto fail;
  371. }
  372. memcpy(dst->extended_data, src->extended_data, sizeof(*src->extended_data) * ch);
  373. } else
  374. dst->extended_data = dst->data;
  375. memcpy(dst->data, src->data, sizeof(src->data));
  376. memcpy(dst->linesize, src->linesize, sizeof(src->linesize));
  377. return 0;
  378. fail:
  379. av_frame_unref(dst);
  380. return ret;
  381. }
  382. AVFrame *av_frame_clone(const AVFrame *src)
  383. {
  384. AVFrame *ret = av_frame_alloc();
  385. if (!ret)
  386. return NULL;
  387. if (av_frame_ref(ret, src) < 0)
  388. av_frame_free(&ret);
  389. return ret;
  390. }
  391. void av_frame_unref(AVFrame *frame)
  392. {
  393. int i;
  394. if (!frame)
  395. return;
  396. wipe_side_data(frame);
  397. for (i = 0; i < FF_ARRAY_ELEMS(frame->buf); i++)
  398. av_buffer_unref(&frame->buf[i]);
  399. for (i = 0; i < frame->nb_extended_buf; i++)
  400. av_buffer_unref(&frame->extended_buf[i]);
  401. av_freep(&frame->extended_buf);
  402. av_dict_free(&frame->metadata);
  403. av_buffer_unref(&frame->qp_table_buf);
  404. get_frame_defaults(frame);
  405. }
  406. void av_frame_move_ref(AVFrame *dst, AVFrame *src)
  407. {
  408. *dst = *src;
  409. if (src->extended_data == src->data)
  410. dst->extended_data = dst->data;
  411. memset(src, 0, sizeof(*src));
  412. get_frame_defaults(src);
  413. }
  414. int av_frame_is_writable(AVFrame *frame)
  415. {
  416. int i, ret = 1;
  417. /* assume non-refcounted frames are not writable */
  418. if (!frame->buf[0])
  419. return 0;
  420. for (i = 0; i < FF_ARRAY_ELEMS(frame->buf); i++)
  421. if (frame->buf[i])
  422. ret &= !!av_buffer_is_writable(frame->buf[i]);
  423. for (i = 0; i < frame->nb_extended_buf; i++)
  424. ret &= !!av_buffer_is_writable(frame->extended_buf[i]);
  425. return ret;
  426. }
  427. int av_frame_make_writable(AVFrame *frame)
  428. {
  429. AVFrame tmp;
  430. int ret;
  431. if (!frame->buf[0])
  432. return AVERROR(EINVAL);
  433. if (av_frame_is_writable(frame))
  434. return 0;
  435. memset(&tmp, 0, sizeof(tmp));
  436. tmp.format = frame->format;
  437. tmp.width = frame->width;
  438. tmp.height = frame->height;
  439. tmp.channels = frame->channels;
  440. tmp.channel_layout = frame->channel_layout;
  441. tmp.nb_samples = frame->nb_samples;
  442. ret = av_frame_get_buffer(&tmp, 32);
  443. if (ret < 0)
  444. return ret;
  445. ret = av_frame_copy(&tmp, frame);
  446. if (ret < 0) {
  447. av_frame_unref(&tmp);
  448. return ret;
  449. }
  450. ret = av_frame_copy_props(&tmp, frame);
  451. if (ret < 0) {
  452. av_frame_unref(&tmp);
  453. return ret;
  454. }
  455. av_frame_unref(frame);
  456. *frame = tmp;
  457. if (tmp.data == tmp.extended_data)
  458. frame->extended_data = frame->data;
  459. return 0;
  460. }
  461. int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
  462. {
  463. return frame_copy_props(dst, src, 1);
  464. }
  465. AVBufferRef *av_frame_get_plane_buffer(AVFrame *frame, int plane)
  466. {
  467. uint8_t *data;
  468. int planes, i;
  469. if (frame->nb_samples) {
  470. int channels = frame->channels;
  471. if (!channels)
  472. return NULL;
  473. CHECK_CHANNELS_CONSISTENCY(frame);
  474. planes = av_sample_fmt_is_planar(frame->format) ? channels : 1;
  475. } else
  476. planes = 4;
  477. if (plane < 0 || plane >= planes || !frame->extended_data[plane])
  478. return NULL;
  479. data = frame->extended_data[plane];
  480. for (i = 0; i < FF_ARRAY_ELEMS(frame->buf) && frame->buf[i]; i++) {
  481. AVBufferRef *buf = frame->buf[i];
  482. if (data >= buf->data && data < buf->data + buf->size)
  483. return buf;
  484. }
  485. for (i = 0; i < frame->nb_extended_buf; i++) {
  486. AVBufferRef *buf = frame->extended_buf[i];
  487. if (data >= buf->data && data < buf->data + buf->size)
  488. return buf;
  489. }
  490. return NULL;
  491. }
  492. AVFrameSideData *av_frame_new_side_data(AVFrame *frame,
  493. enum AVFrameSideDataType type,
  494. int size)
  495. {
  496. AVFrameSideData *ret, **tmp;
  497. if (frame->nb_side_data > INT_MAX / sizeof(*frame->side_data) - 1)
  498. return NULL;
  499. tmp = av_realloc(frame->side_data,
  500. (frame->nb_side_data + 1) * sizeof(*frame->side_data));
  501. if (!tmp)
  502. return NULL;
  503. frame->side_data = tmp;
  504. ret = av_mallocz(sizeof(*ret));
  505. if (!ret)
  506. return NULL;
  507. if (size > 0) {
  508. ret->buf = av_buffer_alloc(size);
  509. if (!ret->buf) {
  510. av_freep(&ret);
  511. return NULL;
  512. }
  513. ret->data = ret->buf->data;
  514. ret->size = size;
  515. }
  516. ret->type = type;
  517. frame->side_data[frame->nb_side_data++] = ret;
  518. return ret;
  519. }
  520. AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,
  521. enum AVFrameSideDataType type)
  522. {
  523. int i;
  524. for (i = 0; i < frame->nb_side_data; i++) {
  525. if (frame->side_data[i]->type == type)
  526. return frame->side_data[i];
  527. }
  528. return NULL;
  529. }
  530. static int frame_copy_video(AVFrame *dst, const AVFrame *src)
  531. {
  532. const uint8_t *src_data[4];
  533. int i, planes;
  534. if (dst->width < src->width ||
  535. dst->height < src->height)
  536. return AVERROR(EINVAL);
  537. planes = av_pix_fmt_count_planes(dst->format);
  538. for (i = 0; i < planes; i++)
  539. if (!dst->data[i] || !src->data[i])
  540. return AVERROR(EINVAL);
  541. memcpy(src_data, src->data, sizeof(src_data));
  542. av_image_copy(dst->data, dst->linesize,
  543. src_data, src->linesize,
  544. dst->format, src->width, src->height);
  545. return 0;
  546. }
  547. static int frame_copy_audio(AVFrame *dst, const AVFrame *src)
  548. {
  549. int planar = av_sample_fmt_is_planar(dst->format);
  550. int channels = dst->channels;
  551. int planes = planar ? channels : 1;
  552. int i;
  553. if (dst->nb_samples != src->nb_samples ||
  554. dst->channels != src->channels ||
  555. dst->channel_layout != src->channel_layout)
  556. return AVERROR(EINVAL);
  557. CHECK_CHANNELS_CONSISTENCY(src);
  558. for (i = 0; i < planes; i++)
  559. if (!dst->extended_data[i] || !src->extended_data[i])
  560. return AVERROR(EINVAL);
  561. av_samples_copy(dst->extended_data, src->extended_data, 0, 0,
  562. dst->nb_samples, channels, dst->format);
  563. return 0;
  564. }
  565. int av_frame_copy(AVFrame *dst, const AVFrame *src)
  566. {
  567. if (dst->format != src->format || dst->format < 0)
  568. return AVERROR(EINVAL);
  569. if (dst->width > 0 && dst->height > 0)
  570. return frame_copy_video(dst, src);
  571. else if (dst->nb_samples > 0 && dst->channel_layout)
  572. return frame_copy_audio(dst, src);
  573. return AVERROR(EINVAL);
  574. }
  575. void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type)
  576. {
  577. int i;
  578. for (i = 0; i < frame->nb_side_data; i++) {
  579. AVFrameSideData *sd = frame->side_data[i];
  580. if (sd->type == type) {
  581. free_side_data(&frame->side_data[i]);
  582. frame->side_data[i] = frame->side_data[frame->nb_side_data - 1];
  583. frame->nb_side_data--;
  584. }
  585. }
  586. }
  587. const char *av_frame_side_data_name(enum AVFrameSideDataType type)
  588. {
  589. switch(type) {
  590. case AV_FRAME_DATA_PANSCAN: return "AVPanScan";
  591. case AV_FRAME_DATA_A53_CC: return "ATSC A53 Part 4 Closed Captions";
  592. case AV_FRAME_DATA_STEREO3D: return "Stereoscopic 3d metadata";
  593. case AV_FRAME_DATA_MATRIXENCODING: return "AVMatrixEncoding";
  594. case AV_FRAME_DATA_DOWNMIX_INFO: return "Metadata relevant to a downmix procedure";
  595. case AV_FRAME_DATA_REPLAYGAIN: return "AVReplayGain";
  596. case AV_FRAME_DATA_DISPLAYMATRIX: return "3x3 displaymatrix";
  597. case AV_FRAME_DATA_MOTION_VECTORS: return "Motion vectors";
  598. }
  599. return NULL;
  600. }