libdcp
ffmpeg_image.h
1 /*
2  Copyright (C) 2023 Carl Hetherington <cth@carlh.net>
3 
4  This file is part of libdcp.
5 
6  libdcp is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  libdcp is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with libdcp. If not, see <http://www.gnu.org/licenses/>.
18 
19  In addition, as a special exception, the copyright holders give
20  permission to link the code of portions of this program with the
21  OpenSSL library under certain conditions as described in each
22  individual source file, and distribute linked combinations
23  including the two.
24 
25  You must obey the GNU General Public License in all respects
26  for all of the code used other than OpenSSL. If you modify
27  file(s) with this exception, you may extend this exception to your
28  version of the file(s), but you are not obligated to do so. If you
29  do not wish to do so, delete this exception statement from your
30  version. If you delete this exception statement from all source
31  files in the program, then also delete it here.
32 */
33 
34 
35 #ifndef LIBDCP_FFMPEG_IMAGE_H
36 #define LIBDCP_FFMPEG_IMAGE_H
37 
38 
39 #include "types.h"
40 #include "warnings.h"
41 LIBDCP_DISABLE_WARNINGS
42 extern "C" {
43 #include <libavutil/frame.h>
44 }
45 LIBDCP_ENABLE_WARNINGS
46 #include <algorithm>
47 #include <vector>
48 
49 
50 namespace dcp {
51 
52 
54 {
55 public:
56  explicit FFmpegImage(int64_t pts);
57 
58  explicit FFmpegImage(AVFrame* frame)
59  : _frame(frame)
60  {}
61 
62  FFmpegImage(FFmpegImage const& other) = delete;
63  FFmpegImage& operator=(FFmpegImage const& other) = delete;
64 
65  FFmpegImage(FFmpegImage&& other) {
66  std::swap(_frame, other._frame);
67  }
68 
69  FFmpegImage& operator=(FFmpegImage&& other) {
70  std::swap(_frame, other._frame);
71  return *this;
72  }
73 
74  ~FFmpegImage()
75  {
76  av_frame_free(&_frame);
77  }
78 
79  AVFrame const * frame() const {
80  return _frame;
81  }
82 
83  uint8_t* y();
84  int y_stride() const;
85 
86  uint8_t* u();
87  int u_stride() const;
88 
89  uint8_t* v();
90  int v_stride() const;
91 
92  Size size() const {
93  return { 1920, 1080 };
94  }
95 
96  void set_pts(int64_t pts);
97 
98 private:
99  AVFrame* _frame = nullptr;
100 };
101 
102 
103 }
104 
105 
106 #endif
107 
Namespace for everything in libdcp.
Definition: array_data.h:50
The integer, two-dimensional size of something.
Definition: types.h:71
Miscellaneous types.