yading@10
|
1 /*
|
yading@10
|
2 * This file is part of FFmpeg.
|
yading@10
|
3 *
|
yading@10
|
4 * FFmpeg is free software; you can redistribute it and/or
|
yading@10
|
5 * modify it under the terms of the GNU Lesser General Public
|
yading@10
|
6 * License as published by the Free Software Foundation; either
|
yading@10
|
7 * version 2.1 of the License, or (at your option) any later version.
|
yading@10
|
8 *
|
yading@10
|
9 * FFmpeg is distributed in the hope that it will be useful,
|
yading@10
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
yading@10
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
yading@10
|
12 * Lesser General Public License for more details.
|
yading@10
|
13 *
|
yading@10
|
14 * You should have received a copy of the GNU Lesser General Public
|
yading@10
|
15 * License along with FFmpeg; if not, write to the Free Software
|
yading@10
|
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
yading@10
|
17 */
|
yading@10
|
18
|
yading@10
|
19 /**
|
yading@10
|
20 * @file
|
yading@10
|
21 * common internal api header.
|
yading@10
|
22 */
|
yading@10
|
23
|
yading@10
|
24 #ifndef AVCODEC_INTERNAL_H
|
yading@10
|
25 #define AVCODEC_INTERNAL_H
|
yading@10
|
26
|
yading@10
|
27 #include <stdint.h>
|
yading@10
|
28
|
yading@10
|
29 #include "libavutil/buffer.h"
|
yading@10
|
30 #include "libavutil/mathematics.h"
|
yading@10
|
31 #include "libavutil/pixfmt.h"
|
yading@10
|
32 #include "avcodec.h"
|
yading@10
|
33 #include "config.h"
|
yading@10
|
34
|
yading@10
|
35 #define FF_SANE_NB_CHANNELS 63U
|
yading@10
|
36
|
yading@10
|
37 typedef struct FramePool {
|
yading@10
|
38 /**
|
yading@10
|
39 * Pools for each data plane. For audio all the planes have the same size,
|
yading@10
|
40 * so only pools[0] is used.
|
yading@10
|
41 */
|
yading@10
|
42 AVBufferPool *pools[4];
|
yading@10
|
43
|
yading@10
|
44 /*
|
yading@10
|
45 * Pool parameters
|
yading@10
|
46 */
|
yading@10
|
47 int format;
|
yading@10
|
48 int width, height;
|
yading@10
|
49 int stride_align[AV_NUM_DATA_POINTERS];
|
yading@10
|
50 int linesize[4];
|
yading@10
|
51 int planes;
|
yading@10
|
52 int channels;
|
yading@10
|
53 int samples;
|
yading@10
|
54 } FramePool;
|
yading@10
|
55
|
yading@10
|
56 typedef struct AVCodecInternal {
|
yading@10
|
57 /**
|
yading@10
|
58 * Whether the parent AVCodecContext is a copy of the context which had
|
yading@10
|
59 * init() called on it.
|
yading@10
|
60 * This is used by multithreading - shared tables and picture pointers
|
yading@10
|
61 * should be freed from the original context only.
|
yading@10
|
62 */
|
yading@10
|
63 int is_copy;
|
yading@10
|
64
|
yading@10
|
65 /**
|
yading@10
|
66 * Whether to allocate progress for frame threading.
|
yading@10
|
67 *
|
yading@10
|
68 * The codec must set it to 1 if it uses ff_thread_await/report_progress(),
|
yading@10
|
69 * then progress will be allocated in ff_thread_get_buffer(). The frames
|
yading@10
|
70 * then MUST be freed with ff_thread_release_buffer().
|
yading@10
|
71 *
|
yading@10
|
72 * If the codec does not need to call the progress functions (there are no
|
yading@10
|
73 * dependencies between the frames), it should leave this at 0. Then it can
|
yading@10
|
74 * decode straight to the user-provided frames (which the user will then
|
yading@10
|
75 * free with av_frame_unref()), there is no need to call
|
yading@10
|
76 * ff_thread_release_buffer().
|
yading@10
|
77 */
|
yading@10
|
78 int allocate_progress;
|
yading@10
|
79
|
yading@10
|
80 #if FF_API_OLD_ENCODE_AUDIO
|
yading@10
|
81 /**
|
yading@10
|
82 * Internal sample count used by avcodec_encode_audio() to fabricate pts.
|
yading@10
|
83 * Can be removed along with avcodec_encode_audio().
|
yading@10
|
84 */
|
yading@10
|
85 int sample_count;
|
yading@10
|
86 #endif
|
yading@10
|
87
|
yading@10
|
88 /**
|
yading@10
|
89 * An audio frame with less than required samples has been submitted and
|
yading@10
|
90 * padded with silence. Reject all subsequent frames.
|
yading@10
|
91 */
|
yading@10
|
92 int last_audio_frame;
|
yading@10
|
93
|
yading@10
|
94 AVFrame to_free;
|
yading@10
|
95
|
yading@10
|
96 FramePool *pool;
|
yading@10
|
97
|
yading@10
|
98 /**
|
yading@10
|
99 * temporary buffer used for encoders to store their bitstream
|
yading@10
|
100 */
|
yading@10
|
101 uint8_t *byte_buffer;
|
yading@10
|
102 unsigned int byte_buffer_size;
|
yading@10
|
103
|
yading@10
|
104 void *frame_thread_encoder;
|
yading@10
|
105
|
yading@10
|
106 /**
|
yading@10
|
107 * Number of audio samples to skip at the start of the next decoded frame
|
yading@10
|
108 */
|
yading@10
|
109 int skip_samples;
|
yading@10
|
110 } AVCodecInternal;
|
yading@10
|
111
|
yading@10
|
112 struct AVCodecDefault {
|
yading@10
|
113 const uint8_t *key;
|
yading@10
|
114 const uint8_t *value;
|
yading@10
|
115 };
|
yading@10
|
116
|
yading@10
|
117 /**
|
yading@10
|
118 * Return the hardware accelerated codec for codec codec_id and
|
yading@10
|
119 * pixel format pix_fmt.
|
yading@10
|
120 *
|
yading@10
|
121 * @param codec_id the codec to match
|
yading@10
|
122 * @param pix_fmt the pixel format to match
|
yading@10
|
123 * @return the hardware accelerated codec, or NULL if none was found.
|
yading@10
|
124 */
|
yading@10
|
125 AVHWAccel *ff_find_hwaccel(enum AVCodecID codec_id, enum AVPixelFormat pix_fmt);
|
yading@10
|
126
|
yading@10
|
127 /**
|
yading@10
|
128 * Return the index into tab at which {a,b} match elements {[0],[1]} of tab.
|
yading@10
|
129 * If there is no such matching pair then size is returned.
|
yading@10
|
130 */
|
yading@10
|
131 int ff_match_2uint16(const uint16_t (*tab)[2], int size, int a, int b);
|
yading@10
|
132
|
yading@10
|
133 unsigned int avpriv_toupper4(unsigned int x);
|
yading@10
|
134
|
yading@10
|
135 /**
|
yading@10
|
136 * does needed setup of pkt_pts/pos and such for (re)get_buffer();
|
yading@10
|
137 */
|
yading@10
|
138 int ff_init_buffer_info(AVCodecContext *s, AVFrame *frame);
|
yading@10
|
139
|
yading@10
|
140
|
yading@10
|
141 void avpriv_color_frame(AVFrame *frame, const int color[4]);
|
yading@10
|
142
|
yading@10
|
143 /**
|
yading@10
|
144 * Remove and free all side data from packet.
|
yading@10
|
145 */
|
yading@10
|
146 void ff_packet_free_side_data(AVPacket *pkt);
|
yading@10
|
147
|
yading@10
|
148 extern volatile int ff_avcodec_locked;
|
yading@10
|
149 int ff_lock_avcodec(AVCodecContext *log_ctx);
|
yading@10
|
150 int ff_unlock_avcodec(void);
|
yading@10
|
151
|
yading@10
|
152 int avpriv_lock_avformat(void);
|
yading@10
|
153 int avpriv_unlock_avformat(void);
|
yading@10
|
154
|
yading@10
|
155 /**
|
yading@10
|
156 * Maximum size in bytes of extradata.
|
yading@10
|
157 * This value was chosen such that every bit of the buffer is
|
yading@10
|
158 * addressable by a 32-bit signed integer as used by get_bits.
|
yading@10
|
159 */
|
yading@10
|
160 #define FF_MAX_EXTRADATA_SIZE ((1 << 28) - FF_INPUT_BUFFER_PADDING_SIZE)
|
yading@10
|
161
|
yading@10
|
162 /**
|
yading@10
|
163 * Check AVPacket size and/or allocate data.
|
yading@10
|
164 *
|
yading@10
|
165 * Encoders supporting AVCodec.encode2() can use this as a convenience to
|
yading@10
|
166 * ensure the output packet data is large enough, whether provided by the user
|
yading@10
|
167 * or allocated in this function.
|
yading@10
|
168 *
|
yading@10
|
169 * @param avctx the AVCodecContext of the encoder
|
yading@10
|
170 * @param avpkt the AVPacket
|
yading@10
|
171 * If avpkt->data is already set, avpkt->size is checked
|
yading@10
|
172 * to ensure it is large enough.
|
yading@10
|
173 * If avpkt->data is NULL, a new buffer is allocated.
|
yading@10
|
174 * avpkt->size is set to the specified size.
|
yading@10
|
175 * All other AVPacket fields will be reset with av_init_packet().
|
yading@10
|
176 * @param size the minimum required packet size
|
yading@10
|
177 * @return 0 on success, negative error code on failure
|
yading@10
|
178 */
|
yading@10
|
179 int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int size);
|
yading@10
|
180
|
yading@10
|
181 int ff_alloc_packet(AVPacket *avpkt, int size);
|
yading@10
|
182
|
yading@10
|
183 /**
|
yading@10
|
184 * Rescale from sample rate to AVCodecContext.time_base.
|
yading@10
|
185 */
|
yading@10
|
186 static av_always_inline int64_t ff_samples_to_time_base(AVCodecContext *avctx,
|
yading@10
|
187 int64_t samples)
|
yading@10
|
188 {
|
yading@10
|
189 if(samples == AV_NOPTS_VALUE)
|
yading@10
|
190 return AV_NOPTS_VALUE;
|
yading@10
|
191 return av_rescale_q(samples, (AVRational){ 1, avctx->sample_rate },
|
yading@10
|
192 avctx->time_base);
|
yading@10
|
193 }
|
yading@10
|
194
|
yading@10
|
195 /**
|
yading@10
|
196 * Get a buffer for a frame. This is a wrapper around
|
yading@10
|
197 * AVCodecContext.get_buffer() and should be used instead calling get_buffer()
|
yading@10
|
198 * directly.
|
yading@10
|
199 */
|
yading@10
|
200 int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags);
|
yading@10
|
201
|
yading@10
|
202 /**
|
yading@10
|
203 * Identical in function to av_frame_make_writable(), except it uses
|
yading@10
|
204 * ff_get_buffer() to allocate the buffer when needed.
|
yading@10
|
205 */
|
yading@10
|
206 int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame);
|
yading@10
|
207
|
yading@10
|
208 int ff_thread_can_start_frame(AVCodecContext *avctx);
|
yading@10
|
209
|
yading@10
|
210 int ff_get_logical_cpus(AVCodecContext *avctx);
|
yading@10
|
211
|
yading@10
|
212 int avpriv_h264_has_num_reorder_frames(AVCodecContext *avctx);
|
yading@10
|
213
|
yading@10
|
214 /**
|
yading@10
|
215 * Call avcodec_open2 recursively by decrementing counter, unlocking mutex,
|
yading@10
|
216 * calling the function and then restoring again. Assumes the mutex is
|
yading@10
|
217 * already locked
|
yading@10
|
218 */
|
yading@10
|
219 int ff_codec_open2_recursive(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options);
|
yading@10
|
220
|
yading@10
|
221 /**
|
yading@10
|
222 * Call avcodec_close recursively, counterpart to avcodec_open2_recursive.
|
yading@10
|
223 */
|
yading@10
|
224 int ff_codec_close_recursive(AVCodecContext *avctx);
|
yading@10
|
225
|
yading@10
|
226 /**
|
yading@10
|
227 * Finalize buf into extradata and set its size appropriately.
|
yading@10
|
228 */
|
yading@10
|
229 int avpriv_bprint_to_extradata(AVCodecContext *avctx, struct AVBPrint *buf);
|
yading@10
|
230
|
yading@10
|
231 const uint8_t *avpriv_find_start_code(const uint8_t *p,
|
yading@10
|
232 const uint8_t *end,
|
yading@10
|
233 uint32_t *state);
|
yading@10
|
234
|
yading@10
|
235 #endif /* AVCODEC_INTERNAL_H */
|