ffmpeg_utils.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef FFTOOLS_FFMPEG_UTILS_H
  19. #define FFTOOLS_FFMPEG_UTILS_H
  20. #include <stdint.h>
  21. #include "libavutil/common.h"
  22. #include "libavutil/frame.h"
  23. #include "libavutil/rational.h"
  24. #include "libavcodec/packet.h"
  25. typedef struct Timestamp {
  26. int64_t ts;
  27. AVRational tb;
  28. } Timestamp;
  29. /**
  30. * Merge two return codes - return one of the error codes if at least one of
  31. * them was negative, 0 otherwise.
  32. */
  33. static inline int err_merge(int err0, int err1)
  34. {
  35. // prefer "real" errors over EOF
  36. if ((err0 >= 0 || err0 == AVERROR_EOF) && err1 < 0)
  37. return err1;
  38. return (err0 < 0) ? err0 : FFMIN(err1, 0);
  39. }
  40. /**
  41. * Wrapper calling av_frame_side_data_clone() in a loop for all source entries.
  42. * It does not clear dst beforehand. */
  43. static inline int clone_side_data(AVFrameSideData ***dst, int *nb_dst,
  44. AVFrameSideData * const *src, int nb_src,
  45. unsigned int flags)
  46. {
  47. for (int i = 0; i < nb_src; i++) {
  48. int ret = av_frame_side_data_clone(dst, nb_dst, src[i], flags);
  49. if (ret < 0)
  50. return ret;
  51. }
  52. return 0;
  53. }
  54. #endif // FFTOOLS_FFMPEG_UTILS_H