#include "libavutil/integer.h"#include "libavutil/crc.h"#include "avcodec.h"#include "dsputil.h"#include "opt.h"#include "imgconvert.h"#include <stdarg.h>#include <limits.h>#include <float.h>#include <fcntl.h>Go to the source code of this file.
Data Structures | |
| struct | InternalBuffer |
| struct | VideoFrameSizeAbbr |
| struct | VideoFrameRateAbbr |
Defines | |
| #define | INTERNAL_BUFFER_SIZE 32 |
| #define | ALIGN(x, a) (((x)+(a)-1)&~((a)-1)) |
| #define | OFFSET(x) offsetof(AVCodecContext,x) |
| #define | DEFAULT 0 |
| #define | V AV_OPT_FLAG_VIDEO_PARAM |
| #define | A AV_OPT_FLAG_AUDIO_PARAM |
| #define | S AV_OPT_FLAG_SUBTITLE_PARAM |
| #define | E AV_OPT_FLAG_ENCODING_PARAM |
| #define | D AV_OPT_FLAG_DECODING_PARAM |
| #define | AV_CODEC_DEFAULT_BITRATE 200*1000 |
Functions | |
| void * | av_fast_realloc (void *ptr, unsigned int *size, unsigned int min_size) |
| AVCodec * | av_codec_next (AVCodec *c) |
| void | register_avcodec (AVCodec *format) |
| void | avcodec_set_dimensions (AVCodecContext *s, int width, int height) |
| void | avcodec_align_dimensions (AVCodecContext *s, int *width, int *height) |
| int | avcodec_check_dimensions (void *av_log_ctx, unsigned int w, unsigned int h) |
| int | avcodec_default_get_buffer (AVCodecContext *s, AVFrame *pic) |
| void | avcodec_default_release_buffer (AVCodecContext *s, AVFrame *pic) |
| int | avcodec_default_reget_buffer (AVCodecContext *s, AVFrame *pic) |
| int | avcodec_default_execute (AVCodecContext *c, int(*func)(AVCodecContext *c2, void *arg2), void **arg, int *ret, int count) |
| enum PixelFormat | avcodec_default_get_format (struct AVCodecContext *s, const enum PixelFormat *fmt) |
| static const char * | context_to_name (void *ptr) |
| void | avcodec_get_context_defaults2 (AVCodecContext *s, enum CodecType codec_type) |
| AVCodecContext * | avcodec_alloc_context2 (enum CodecType codec_type) |
| void | avcodec_get_context_defaults (AVCodecContext *s) |
| AVCodecContext * | avcodec_alloc_context (void) |
| void | avcodec_get_frame_defaults (AVFrame *pic) |
| AVFrame * | avcodec_alloc_frame (void) |
| int attribute_align_arg | avcodec_open (AVCodecContext *avctx, AVCodec *codec) |
| int attribute_align_arg | avcodec_encode_audio (AVCodecContext *avctx, uint8_t *buf, int buf_size, const short *samples) |
| int attribute_align_arg | avcodec_encode_video (AVCodecContext *avctx, uint8_t *buf, int buf_size, const AVFrame *pict) |
| int | avcodec_encode_subtitle (AVCodecContext *avctx, uint8_t *buf, int buf_size, const AVSubtitle *sub) |
| int attribute_align_arg | avcodec_decode_video (AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, const uint8_t *buf, int buf_size) |
| int attribute_align_arg | avcodec_decode_audio2 (AVCodecContext *avctx, int16_t *samples, int *frame_size_ptr, const uint8_t *buf, int buf_size) |
| int | avcodec_decode_subtitle (AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, const uint8_t *buf, int buf_size) |
| int | avcodec_close (AVCodecContext *avctx) |
| AVCodec * | avcodec_find_encoder (enum CodecID id) |
| AVCodec * | avcodec_find_encoder_by_name (const char *name) |
| AVCodec * | avcodec_find_decoder (enum CodecID id) |
| AVCodec * | avcodec_find_decoder_by_name (const char *name) |
| void | avcodec_string (char *buf, int buf_size, AVCodecContext *enc, int encode) |
| unsigned | avcodec_version (void) |
| void | avcodec_init (void) |
| void | avcodec_flush_buffers (AVCodecContext *avctx) |
| void | avcodec_default_free_buffers (AVCodecContext *s) |
| char | av_get_pict_type_char (int pict_type) |
| int | av_get_bits_per_sample (enum CodecID codec_id) |
| int | av_get_bits_per_sample_format (enum SampleFormat sample_fmt) |
| int | avcodec_thread_init (AVCodecContext *s, int thread_count) |
| unsigned int | av_xiphlacing (unsigned char *s, unsigned int v) |
| int | av_tempfile (char *prefix, char **filename) |
| int | av_parse_video_frame_size (int *width_ptr, int *height_ptr, const char *str) |
| int | av_parse_video_frame_rate (AVRational *frame_rate, const char *arg) |
Variables | |
| const uint8_t | ff_reverse [256] |
| AVCodec * | first_avcodec = NULL |
| static const AVOption | options [] |
| static const AVClass | av_codec_context_class = { "AVCodecContext", context_to_name, options } |
| static const VideoFrameSizeAbbr | video_frame_size_abbrs [] |
| static const VideoFrameRateAbbr | video_frame_rate_abbrs [] |
| #define A AV_OPT_FLAG_AUDIO_PARAM |
Definition at line 369 of file libavcodec/utils.c.
Referenced by av_random_generate_untempered_numbers(), find_and_decode_index(), gmc1_c(), gmc_c(), h263_pred_motion(), horizX1Filter(), idct(), md5_process_block(), pred_16x8_motion(), pred_8x16_motion(), pred_motion(), predictor_decode_mono(), put_no_rnd_h264_chroma_mc8_c(), rv30_decode_intra_types(), rv34_pred_mv(), rv34_pred_mv_b(), rv40_decode_intra_types(), sha1_process(), vc1_pred_b_mv(), vc1_pred_mv(), wmv2_pred_motion(), wv_unpack_mono(), and wv_unpack_stereo().
| #define ALIGN | ( | x, | |||
| a | ) | (((x)+(a)-1)&~((a)-1)) |
Definition at line 109 of file libavcodec/utils.c.
| #define AV_CODEC_DEFAULT_BITRATE 200*1000 |
Definition at line 374 of file libavcodec/utils.c.
| #define D AV_OPT_FLAG_DECODING_PARAM |
Definition at line 372 of file libavcodec/utils.c.
Referenced by gmc1_c(), gmc_c(), horizX1Filter(), idct(), md5_process_block(), put_no_rnd_h264_chroma_mc8_c(), and sha1_process().
| #define DEFAULT 0 |
Definition at line 366 of file libavcodec/utils.c.
| #define E AV_OPT_FLAG_ENCODING_PARAM |
| #define INTERNAL_BUFFER_SIZE 32 |
Definition at line 107 of file libavcodec/utils.c.
Referenced by avcodec_default_free_buffers(), and avcodec_default_get_buffer().
| #define OFFSET | ( | x | ) | offsetof(AVCodecContext,x) |
Definition at line 365 of file libavcodec/utils.c.
| #define S AV_OPT_FLAG_SUBTITLE_PARAM |
Definition at line 370 of file libavcodec/utils.c.
Referenced by dering_altivec(), and wv_unpack_mono().
| #define V AV_OPT_FLAG_VIDEO_PARAM |
Definition at line 368 of file libavcodec/utils.c.
Referenced by altivec_uyvy_rgb32(), altivec_yuv2packedX(), decode_frame(), nsv_parse_NSVf_header(), pred16x16_plane_compat_c(), pred8x8_plane_c(), rgb24toyv12(), rv34_mc(), rv34_output_macroblock(), tm2_decode_blocks(), tm2_hi_res_block(), tm2_low_res_block(), tm2_med_res_block(), tm2_motion_block(), tm2_null_res_block(), tm2_still_block(), tm2_update_block(), vp6_adjust(), and yuv2packed2().
Definition at line 77 of file libavcodec/utils.c.
References c, and first_avcodec.
00077 { 00078 if(c) return c->next; 00079 else return first_avcodec; 00080 }
| void* av_fast_realloc | ( | void * | ptr, | |
| unsigned int * | size, | |||
| unsigned int | min_size | |||
| ) |
Reallocates the given block if it is not large enough, otherwise it does nothing.
Definition at line 60 of file libavcodec/utils.c.
References av_realloc(), and FFMAX.
Referenced by allocate_buffers(), av_add_index_entry(), avcodec_default_get_buffer(), decode_frame(), decode_i_frame(), decode_nal(), decode_p_frame(), ff_combine_frame(), ff_h263_decode_frame(), flac_decode_frame(), mp_decode_frame(), output_packet(), read_frame(), and shorten_decode_frame().
00061 { 00062 if(min_size < *size) 00063 return ptr; 00064 00065 *size= FFMAX(17*min_size/16 + 32, min_size); 00066 00067 ptr= av_realloc(ptr, *size); 00068 if(!ptr) //we could set this to the unmodified min_size but this is safer if the user lost the ptr and uses NULL now 00069 *size= 0; 00070 00071 return ptr; 00072 }
| int av_get_bits_per_sample | ( | enum CodecID | codec_id | ) |
Returns codec bits per sample.
| [in] | codec_id | the codec |
Definition at line 1241 of file libavcodec/utils.c.
References CODEC_ID_ADPCM_CT, CODEC_ID_ADPCM_SBPRO_2, CODEC_ID_ADPCM_SBPRO_3, CODEC_ID_ADPCM_SBPRO_4, CODEC_ID_PCM_ALAW, CODEC_ID_PCM_MULAW, CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE, CODEC_ID_PCM_S16LE_PLANAR, CODEC_ID_PCM_S24BE, CODEC_ID_PCM_S24DAUD, CODEC_ID_PCM_S24LE, CODEC_ID_PCM_S32BE, CODEC_ID_PCM_S32LE, CODEC_ID_PCM_S8, CODEC_ID_PCM_U16BE, CODEC_ID_PCM_U16LE, CODEC_ID_PCM_U24BE, CODEC_ID_PCM_U24LE, CODEC_ID_PCM_U32BE, CODEC_ID_PCM_U32LE, and CODEC_ID_PCM_U8.
Referenced by get_aiff_header(), get_audio_frame_size(), mkv_write_tracks(), mov_read_stsd(), pcm_decode_frame(), pcm_read_seek(), raw_read_packet(), and voc_get_packet().
01241 { 01242 switch(codec_id){ 01243 case CODEC_ID_ADPCM_SBPRO_2: 01244 return 2; 01245 case CODEC_ID_ADPCM_SBPRO_3: 01246 return 3; 01247 case CODEC_ID_ADPCM_SBPRO_4: 01248 case CODEC_ID_ADPCM_CT: 01249 return 4; 01250 case CODEC_ID_PCM_ALAW: 01251 case CODEC_ID_PCM_MULAW: 01252 case CODEC_ID_PCM_S8: 01253 case CODEC_ID_PCM_U8: 01254 return 8; 01255 case CODEC_ID_PCM_S16BE: 01256 case CODEC_ID_PCM_S16LE: 01257 case CODEC_ID_PCM_S16LE_PLANAR: 01258 case CODEC_ID_PCM_U16BE: 01259 case CODEC_ID_PCM_U16LE: 01260 return 16; 01261 case CODEC_ID_PCM_S24DAUD: 01262 case CODEC_ID_PCM_S24BE: 01263 case CODEC_ID_PCM_S24LE: 01264 case CODEC_ID_PCM_U24BE: 01265 case CODEC_ID_PCM_U24LE: 01266 return 24; 01267 case CODEC_ID_PCM_S32BE: 01268 case CODEC_ID_PCM_S32LE: 01269 case CODEC_ID_PCM_U32BE: 01270 case CODEC_ID_PCM_U32LE: 01271 return 32; 01272 default: 01273 return 0; 01274 } 01275 }
| int av_get_bits_per_sample_format | ( | enum SampleFormat | sample_fmt | ) |
Returns sample format bits per sample.
| [in] | sample_fmt | the sample format |
Definition at line 1277 of file libavcodec/utils.c.
References SAMPLE_FMT_FLT, SAMPLE_FMT_S16, SAMPLE_FMT_S24, SAMPLE_FMT_S32, and SAMPLE_FMT_U8.
Referenced by mkv_write_tracks().
01277 { 01278 switch (sample_fmt) { 01279 case SAMPLE_FMT_U8: 01280 return 8; 01281 case SAMPLE_FMT_S16: 01282 return 16; 01283 case SAMPLE_FMT_S24: 01284 return 24; 01285 case SAMPLE_FMT_S32: 01286 case SAMPLE_FMT_FLT: 01287 return 32; 01288 default: 01289 return 0; 01290 } 01291 }
| char av_get_pict_type_char | ( | int | pict_type | ) |
Returns a single letter to describe the given picture type pict_type.
| [in] | pict_type | the picture type |
Definition at line 1228 of file libavcodec/utils.c.
References FF_B_TYPE, FF_BI_TYPE, FF_I_TYPE, FF_P_TYPE, FF_S_TYPE, FF_SI_TYPE, and FF_SP_TYPE.
Referenced by decode_mb_cavlc(), do_video_stats(), ff_rate_estimate_qscale(), flv_h263_decode_picture_header(), show_pict_info(), and svq3_decode_frame().
01228 { 01229 switch(pict_type){ 01230 case FF_I_TYPE: return 'I'; 01231 case FF_P_TYPE: return 'P'; 01232 case FF_B_TYPE: return 'B'; 01233 case FF_S_TYPE: return 'S'; 01234 case FF_SI_TYPE:return 'i'; 01235 case FF_SP_TYPE:return 'p'; 01236 case FF_BI_TYPE:return 'b'; 01237 default: return '?'; 01238 } 01239 }
| int av_parse_video_frame_rate | ( | AVRational * | frame_rate, | |
| const char * | str | |||
| ) |
Parses str and put in frame_rate the detected values.
| [in] | str | the string to parse: it has to be a string in the format <frame_rate_nom>/<frame_rate_den>, a float number or a valid video rate abbreviation |
| [in,out] | frame_rate | pointer to the AVRational which will contain the detected frame rate |
Definition at line 1437 of file libavcodec/utils.c.
References av_d2q(), DEFAULT_FRAME_RATE_BASE, AVRational::den, frame_rate, AVRational::num, VideoFrameRateAbbr::rate_den, VideoFrameRateAbbr::rate_num, and video_frame_rate_abbrs.
Referenced by opt_frame_rate(), parse_ffconfig(), and parse_frame_rate().
01438 { 01439 int i; 01440 int n = sizeof(video_frame_rate_abbrs) / sizeof(VideoFrameRateAbbr); 01441 char* cp; 01442 01443 /* First, we check our abbreviation table */ 01444 for (i = 0; i < n; ++i) 01445 if (!strcmp(video_frame_rate_abbrs[i].abbr, arg)) { 01446 frame_rate->num = video_frame_rate_abbrs[i].rate_num; 01447 frame_rate->den = video_frame_rate_abbrs[i].rate_den; 01448 return 0; 01449 } 01450 01451 /* Then, we try to parse it as fraction */ 01452 cp = strchr(arg, '/'); 01453 if (!cp) 01454 cp = strchr(arg, ':'); 01455 if (cp) { 01456 char* cpp; 01457 frame_rate->num = strtol(arg, &cpp, 10); 01458 if (cpp != arg || cpp == cp) 01459 frame_rate->den = strtol(cp+1, &cpp, 10); 01460 else 01461 frame_rate->num = 0; 01462 } 01463 else { 01464 /* Finally we give up and parse it as double */ 01465 AVRational time_base = av_d2q(strtod(arg, 0), DEFAULT_FRAME_RATE_BASE); 01466 frame_rate->den = time_base.den; 01467 frame_rate->num = time_base.num; 01468 } 01469 if (!frame_rate->num || !frame_rate->den) 01470 return -1; 01471 else 01472 return 0; 01473 }
| int av_parse_video_frame_size | ( | int * | width_ptr, | |
| int * | height_ptr, | |||
| const char * | str | |||
| ) |
Parses str and put in width_ptr and height_ptr the detected values.
| [in] | str | the string to parse: it has to be a string in the format <width>x<height> or a valid video frame size abbreviation. |
| [in,out] | width_ptr | pointer to the variable which will contain the detected frame width value |
| [in,out] | height_ptr | pointer to the variable which will contain the detected frame height value |
Definition at line 1409 of file libavcodec/utils.c.
References frame_height, frame_width, VideoFrameSizeAbbr::height, video_frame_size_abbrs, and width.
Referenced by opt_frame_size(), parse_ffconfig(), and parse_image_size().
01410 { 01411 int i; 01412 int n = sizeof(video_frame_size_abbrs) / sizeof(VideoFrameSizeAbbr); 01413 const char *p; 01414 int frame_width = 0, frame_height = 0; 01415 01416 for(i=0;i<n;i++) { 01417 if (!strcmp(video_frame_size_abbrs[i].abbr, str)) { 01418 frame_width = video_frame_size_abbrs[i].width; 01419 frame_height = video_frame_size_abbrs[i].height; 01420 break; 01421 } 01422 } 01423 if (i == n) { 01424 p = str; 01425 frame_width = strtol(p, (char **)&p, 10); 01426 if (*p) 01427 p++; 01428 frame_height = strtol(p, (char **)&p, 10); 01429 } 01430 if (frame_width <= 0 || frame_height <= 0) 01431 return -1; 01432 *width_ptr = frame_width; 01433 *height_ptr = frame_height; 01434 return 0; 01435 }
| int av_tempfile | ( | char * | prefix, | |
| char ** | filename | |||
| ) |
Definition at line 1318 of file libavcodec/utils.c.
References av_log(), AV_LOG_ERROR, av_malloc(), len, and NULL.
Referenced by ff_xvid_encode_init(), and ff_xvid_rate_control_init().
01318 { 01319 int fd=-1; 01320 #if !defined(HAVE_MKSTEMP) 01321 *filename = tempnam(".", prefix); 01322 #else 01323 size_t len = strlen(prefix) + 12; /* room for "/tmp/" and "XXXXXX\0" */ 01324 *filename = av_malloc(len); 01325 #endif 01326 /* -----common section-----*/ 01327 if (*filename == NULL) { 01328 av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot allocate file name\n"); 01329 return -1; 01330 } 01331 #if !defined(HAVE_MKSTEMP) 01332 fd = open(*filename, O_RDWR | O_BINARY | O_CREAT, 0444); 01333 #else 01334 snprintf(*filename, len, "/tmp/%sXXXXXX", prefix); 01335 fd = mkstemp(*filename); 01336 if (fd < 0) { 01337 snprintf(*filename, len, "./%sXXXXXX", prefix); 01338 fd = mkstemp(*filename); 01339 } 01340 #endif 01341 /* -----common section-----*/ 01342 if (fd < 0) { 01343 av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot open temporary file %s\n", *filename); 01344 return -1; 01345 } 01346 return fd; /* success */ 01347 }
| unsigned int av_xiphlacing | ( | unsigned char * | s, | |
| unsigned int | v | |||
| ) |
Definition at line 1299 of file libavcodec/utils.c.
Referenced by fixup_vorbis_headers(), oggvorbis_encode_init(), and put_main_header().
01300 { 01301 unsigned int n = 0; 01302 01303 while(v >= 0xff) { 01304 *s++ = 0xff; 01305 v -= 0xff; 01306 n++; 01307 } 01308 *s = v; 01309 n++; 01310 return n; 01311 }
| void avcodec_align_dimensions | ( | AVCodecContext * | s, | |
| int * | width, | |||
| int * | height | |||
| ) |
Definition at line 111 of file libavcodec/utils.c.
References ALIGN, AVCodecContext::codec_id, CODEC_ID_MSZH, CODEC_ID_RPZA, CODEC_ID_SMC, CODEC_ID_SVQ1, CODEC_ID_ZLIB, AVCodecContext::pix_fmt, PIX_FMT_BGR24, PIX_FMT_GRAY16BE, PIX_FMT_GRAY16LE, PIX_FMT_GRAY8, PIX_FMT_PAL8, PIX_FMT_RGB555, PIX_FMT_UYVY422, PIX_FMT_UYYVYY411, PIX_FMT_YUV410P, PIX_FMT_YUV411P, PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_YUV444P, PIX_FMT_YUVA420P, PIX_FMT_YUVJ420P, PIX_FMT_YUVJ422P, PIX_FMT_YUVJ444P, and PIX_FMT_YUYV422.
Referenced by avcodec_default_get_buffer().
00111 { 00112 int w_align= 1; 00113 int h_align= 1; 00114 00115 switch(s->pix_fmt){ 00116 case PIX_FMT_YUV420P: 00117 case PIX_FMT_YUYV422: 00118 case PIX_FMT_UYVY422: 00119 case PIX_FMT_YUV422P: 00120 case PIX_FMT_YUV444P: 00121 case PIX_FMT_GRAY8: 00122 case PIX_FMT_GRAY16BE: 00123 case PIX_FMT_GRAY16LE: 00124 case PIX_FMT_YUVJ420P: 00125 case PIX_FMT_YUVJ422P: 00126 case PIX_FMT_YUVJ444P: 00127 case PIX_FMT_YUVA420P: 00128 w_align= 16; //FIXME check for non mpeg style codecs and use less alignment 00129 h_align= 16; 00130 break; 00131 case PIX_FMT_YUV411P: 00132 case PIX_FMT_UYYVYY411: 00133 w_align=32; 00134 h_align=8; 00135 break; 00136 case PIX_FMT_YUV410P: 00137 if(s->codec_id == CODEC_ID_SVQ1){ 00138 w_align=64; 00139 h_align=64; 00140 } 00141 case PIX_FMT_RGB555: 00142 if(s->codec_id == CODEC_ID_RPZA){ 00143 w_align=4; 00144 h_align=4; 00145 } 00146 case PIX_FMT_PAL8: 00147 if(s->codec_id == CODEC_ID_SMC){ 00148 w_align=4; 00149 h_align=4; 00150 } 00151 break; 00152 case PIX_FMT_BGR24: 00153 if((s->codec_id == CODEC_ID_MSZH) || (s->codec_id == CODEC_ID_ZLIB)){ 00154 w_align=4; 00155 h_align=4; 00156 } 00157 break; 00158 default: 00159 w_align= 1; 00160 h_align= 1; 00161 break; 00162 } 00163 00164 *width = ALIGN(*width , w_align); 00165 *height= ALIGN(*height, h_align); 00166 }
| AVCodecContext* avcodec_alloc_context | ( | void | ) |
Allocates an AVCodecContext and sets its fields to default values. The resulting struct can be deallocated by simply calling av_free().
Definition at line 770 of file libavcodec/utils.c.
References avcodec_alloc_context2(), and CODEC_TYPE_UNKNOWN.
Referenced by add_av_stream1(), add_codec(), audio_decode_example(), audio_encode_example(), av_new_stream(), estimate_best_b_count(), libextractor_thumbnailffmpeg_extract(), main(), read_ffserver_streams(), rtp_new_av_stream(), video_decode_example(), and video_encode_example().
00770 { 00771 return avcodec_alloc_context2(CODEC_TYPE_UNKNOWN); 00772 }
| AVCodecContext* avcodec_alloc_context2 | ( | enum | CodecType | ) |
THIS FUNCTION IS NOT YET PART OF THE PUBLIC API! we WILL change its arguments and name a few times!
Definition at line 756 of file libavcodec/utils.c.
References av_malloc(), avcodec_get_context_defaults2(), and NULL.
Referenced by avcodec_alloc_context(), and main().
00756 { 00757 AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext)); 00758 00759 if(avctx==NULL) return NULL; 00760 00761 avcodec_get_context_defaults2(avctx, codec_type); 00762 00763 return avctx; 00764 }
| AVFrame* avcodec_alloc_frame | ( | void | ) |
Allocates an AVFrame and sets its fields to default values. The resulting struct can be deallocated by simply calling av_free().
Definition at line 781 of file libavcodec/utils.c.
References av_malloc(), avcodec_get_frame_defaults(), and NULL.
Referenced by adx_encode_init(), alloc_picture(), encode_init(), Faac_encode_init(), g726_init(), get_watermark_picture(), libgsm_init(), MP3lame_encode_init(), oggvorbis_encode_init(), pcm_encode_init(), roq_dpcm_encode_init(), video_decode_example(), video_encode_example(), video_thread(), and vorbis_encode_init().
00781 { 00782 AVFrame *pic= av_malloc(sizeof(AVFrame)); 00783 00784 if(pic==NULL) return NULL; 00785 00786 avcodec_get_frame_defaults(pic); 00787 00788 return pic; 00789 }
| int avcodec_check_dimensions | ( | void * | av_log_ctx, | |
| unsigned int | w, | |||
| unsigned int | h | |||
| ) |
Checks if the given dimension of a picture is valid, meaning that all bytes of the picture can be addressed with a signed int.
| [in] | w | Width of the picture. |
| [in] | h | Height of the picture. |
Definition at line 168 of file libavcodec/utils.c.
References av_log(), and AV_LOG_ERROR.
Referenced by avcodec_decode_video(), avcodec_default_get_buffer(), avcodec_encode_video(), avcodec_open(), avpicture_fill(), cmv_decode_frame(), codec_reinit(), decode_frame(), decode_init(), dnxhd_decode_frame(), ff_mjpeg_decode_sof(), ff_pnm_decode_header(), flashsv_encode_init(), flv_h263_decode_picture_header(), gif_decode_frame(), iv_decode_frame(), libdirac_decode_frame(), libschroedinger_handle_first_access_unit(), mm_decode_init(), MPV_common_init(), pcx_decode_frame(), ptx_decode_frame(), qtrle_encode_init(), roq_encode_init(), rv20_decode_picture_header(), rv40_parse_slice_header(), sunrast_decode_frame(), tiff_decode_tag(), txd_decode_frame(), vqa_decode_init(), and xan_decode_init().
00168 { 00169 if((int)w>0 && (int)h>0 && (w+128)*(uint64_t)(h+128) < INT_MAX/4) 00170 return 0; 00171 00172 av_log(av_log_ctx, AV_LOG_ERROR, "picture size invalid (%ux%u)\n", w, h); 00173 return -1; 00174 }
| int avcodec_close | ( | AVCodecContext * | avctx | ) |
Definition at line 952 of file libavcodec/utils.c.
References av_freep(), avcodec_default_free_buffers(), avcodec_thread_free(), AVCodec::close, AVCodecContext::codec, NULL, AVCodecContext::priv_data, AVCodecContext::rc_eq, and AVCodecContext::thread_opaque.
Referenced by audio_decode_example(), audio_encode_example(), close_audio(), close_connection(), close_video(), estimate_best_b_count(), get_watermark_picture(), stream_component_close(), video_decode_example(), and video_encode_example().
00953 { 00954 if (ENABLE_THREADS && avctx->thread_opaque) 00955 avcodec_thread_free(avctx); 00956 if (avctx->codec->close) 00957 avctx->codec->close(avctx); 00958 avcodec_default_free_buffers(avctx); 00959 av_freep(&avctx->priv_data); 00960 av_freep(&avctx->rc_eq); 00961 avctx->codec = NULL; 00962 return 0; 00963 }
| int attribute_align_arg avcodec_decode_audio2 | ( | AVCodecContext * | avctx, | |
| int16_t * | samples, | |||
| int * | frame_size_ptr, | |||
| const uint8_t * | buf, | |||
| int | buf_size | |||
| ) |
Decodes an audio frame from buf into samples. The avcodec_decode_audio2() function decodes an audio frame from the input buffer buf of size buf_size. To decode it, it makes use of the audio codec which was coupled with avctx using avcodec_open(). The resulting decoded frame is stored in output buffer samples. If no frame could be decompressed, frame_size_ptr is zero. Otherwise, it is the decompressed frame size in bytes.
frame_size_ptr to the allocated size of the output buffer before calling avcodec_decode_audio2().
The input buffer must be FF_INPUT_BUFFER_PADDING_SIZE larger than the actual read bytes because some optimized bitstream readers read 32 or 64 bits at once and could read over the end.
The end of the input buffer buf should be set to 0 to ensure that no overreading happens for damaged MPEG streams.
buf and output buffer samples. The alignment requirements depend on the CPU: On some CPUs it isn't necessary at all, on others it won't work at all if not aligned and on others it will work but it will have an impact on performance. In practice, the bitstream should have 4 byte alignment at minimum and all sample data should be 16 byte aligned unless the CPU doesn't need it (AltiVec and SSE do). If the linesize is not a multiple of 16 then there's no sense in aligning the start of the buffer to 16.| avctx | the codec context | |
| [out] | samples | the output buffer |
| [in,out] | frame_size_ptr | the output buffer size in bytes |
| [in] | buf | the input buffer |
| [in] | buf_size | the input buffer size in bytes |
Definition at line 901 of file libavcodec/utils.c.
References av_log(), AV_LOG_ERROR, AVCODEC_MAX_AUDIO_FRAME_SIZE, AVCodec::capabilities, AVCodecContext::codec, CODEC_CAP_DELAY, AVCodec::decode, FF_MIN_BUFFER_SIZE, AVCodecContext::frame_number, and AVCodecContext::frame_size.
Referenced by audio_decode_frame(), output_packet(), and try_decode_frame().
00904 { 00905 int ret; 00906 00907 if((avctx->codec->capabilities & CODEC_CAP_DELAY) || buf_size){ 00908 //FIXME remove the check below _after_ ensuring that all audio check that the available space is enough 00909 if(*frame_size_ptr < AVCODEC_MAX_AUDIO_FRAME_SIZE){ 00910 av_log(avctx, AV_LOG_ERROR, "buffer smaller than AVCODEC_MAX_AUDIO_FRAME_SIZE\n"); 00911 return -1; 00912 } 00913 if(*frame_size_ptr < FF_MIN_BUFFER_SIZE || 00914 *frame_size_ptr < avctx->channels * avctx->frame_size * sizeof(int16_t)){ 00915 av_log(avctx, AV_LOG_ERROR, "buffer %d too small\n", *frame_size_ptr); 00916 return -1; 00917 } 00918 00919 ret = avctx->codec->decode(avctx, samples, frame_size_ptr, 00920 buf, buf_size); 00921 avctx->frame_number++; 00922 }else{ 00923 ret= 0; 00924 *frame_size_ptr=0; 00925 } 00926 return ret; 00927 }
| int avcodec_decode_subtitle | ( | AVCodecContext * | avctx, | |
| AVSubtitle * | sub, | |||
| int * | got_sub_ptr, | |||
| const uint8_t * | buf, | |||
| int | buf_size | |||
| ) |
Definition at line 938 of file libavcodec/utils.c.
References AVCodecContext::codec, AVCodec::decode, and AVCodecContext::frame_number.
Referenced by output_packet().
00941 { 00942 int ret; 00943 00944 *got_sub_ptr = 0; 00945 ret = avctx->codec->decode(avctx, sub, got_sub_ptr, 00946 buf, buf_size); 00947 if (*got_sub_ptr) 00948 avctx->frame_number++; 00949 return ret; 00950 }
| int attribute_align_arg avcodec_decode_video | ( | AVCodecContext * | avctx, | |
| AVFrame * | picture, | |||
| int * | got_picture_ptr, | |||
| const uint8_t * | buf, | |||
| int | buf_size | |||
| ) |
Decodes a video frame from buf into picture. The avcodec_decode_video() function decodes a video frame from the input buffer buf of size buf_size. To decode it, it makes use of the video codec which was coupled with avctx using avcodec_open(). The resulting decoded frame is stored in picture.
FF_INPUT_BUFFER_PADDING_SIZE larger than the actual read bytes because some optimized bitstream readers read 32 or 64 bits at once and could read over the end.
The end of the input buffer buf should be set to 0 to ensure that no overreading happens for damaged MPEG streams.
buf and output buffer samples. The alignment requirements depend on the CPU: on some CPUs it isn't necessary at all, on others it won't work at all if not aligned and on others it will work but it will have an impact on performance. In practice, the bitstream should have 4 byte alignment at minimum and all sample data should be 16 byte aligned unless the CPU doesn't need it (AltiVec and SSE do). If the linesize is not a multiple of 16 then there's no sense in aligning the start of the buffer to 16.| avctx | the codec context | |
| [out] | picture | The AVFrame in which the decoded video frame will be stored. |
| [in] | buf | the input buffer |
| [in] | buf_size | the size of the input buffer in bytes |
| [in,out] | got_picture_ptr | Zero if no frame could be decompressed, otherwise, it is nonzero. |
Definition at line 878 of file libavcodec/utils.c.
References avcodec_check_dimensions(), AVCodec::capabilities, AVCodecContext::codec, CODEC_CAP_DELAY, AVCodecContext::coded_height, AVCodecContext::coded_width, AVCodec::decode, emms_c, AVCodecContext::frame_number, and picture.
Referenced by get_watermark_picture(), output_packet(), try_decode_frame(), and video_decode_example().
00881 { 00882 int ret; 00883 00884 *got_picture_ptr= 0; 00885 if((avctx->coded_width||avctx->coded_height) && avcodec_check_dimensions(avctx,avctx->coded_width,avctx->coded_height)) 00886 return -1; 00887 if((avctx->codec->capabilities & CODEC_CAP_DELAY) || buf_size){ 00888 ret = avctx->codec->decode(avctx, picture, got_picture_ptr, 00889 buf, buf_size); 00890 00891 emms_c(); //needed to avoid an emms_c() call before every return; 00892 00893