mirror of
				https://github.com/nyanmisaka/ffmpeg-rockchip.git
				synced 2025-10-31 20:42:49 +08:00 
			
		
		
		
	avcodec: cleanup utils.c
This commit is contained in:
		| @@ -47,23 +47,26 @@ | |||||||
| #include <limits.h> | #include <limits.h> | ||||||
| #include <float.h> | #include <float.h> | ||||||
|  |  | ||||||
| static int volatile entangled_thread_counter=0; | static int volatile entangled_thread_counter = 0; | ||||||
| static int (*ff_lockmgr_cb)(void **mutex, enum AVLockOp op); | static int (*ff_lockmgr_cb)(void **mutex, enum AVLockOp op); | ||||||
| static void *codec_mutex; | static void *codec_mutex; | ||||||
| static void *avformat_mutex; | static void *avformat_mutex; | ||||||
|  |  | ||||||
| void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size) | void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size) | ||||||
| { | { | ||||||
|     if(min_size < *size) |     if (min_size < *size) | ||||||
|         return ptr; |         return ptr; | ||||||
|  |  | ||||||
|     min_size= FFMAX(17*min_size/16 + 32, min_size); |     min_size = FFMAX(17 * min_size / 16 + 32, min_size); | ||||||
|  |  | ||||||
|     ptr= av_realloc(ptr, min_size); |     ptr = av_realloc(ptr, min_size); | ||||||
|     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 |     /* we could set this to the unmodified min_size but this is safer | ||||||
|         min_size= 0; |      * if the user lost the ptr and uses NULL now | ||||||
|  |      */ | ||||||
|  |     if (!ptr) | ||||||
|  |         min_size = 0; | ||||||
|  |  | ||||||
|     *size= min_size; |     *size = min_size; | ||||||
|  |  | ||||||
|     return ptr; |     return ptr; | ||||||
| } | } | ||||||
| @@ -73,11 +76,12 @@ void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size) | |||||||
|     void **p = ptr; |     void **p = ptr; | ||||||
|     if (min_size < *size) |     if (min_size < *size) | ||||||
|         return; |         return; | ||||||
|     min_size= FFMAX(17*min_size/16 + 32, min_size); |     min_size = FFMAX(17 * min_size / 16 + 32, min_size); | ||||||
|     av_free(*p); |     av_free(*p); | ||||||
|     *p = av_malloc(min_size); |     *p = av_malloc(min_size); | ||||||
|     if (!*p) min_size = 0; |     if (!*p) | ||||||
|     *size= min_size; |         min_size = 0; | ||||||
|  |     *size = min_size; | ||||||
| } | } | ||||||
|  |  | ||||||
| void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size) | void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size) | ||||||
| @@ -98,8 +102,10 @@ static AVCodec *first_avcodec = NULL; | |||||||
|  |  | ||||||
| AVCodec *av_codec_next(const AVCodec *c) | AVCodec *av_codec_next(const AVCodec *c) | ||||||
| { | { | ||||||
|     if(c) return c->next; |     if (c) | ||||||
|     else  return first_avcodec; |         return c->next; | ||||||
|  |     else | ||||||
|  |         return first_avcodec; | ||||||
| } | } | ||||||
|  |  | ||||||
| static void avcodec_init(void) | static void avcodec_init(void) | ||||||
| @@ -128,7 +134,8 @@ void avcodec_register(AVCodec *codec) | |||||||
|     AVCodec **p; |     AVCodec **p; | ||||||
|     avcodec_init(); |     avcodec_init(); | ||||||
|     p = &first_avcodec; |     p = &first_avcodec; | ||||||
|     while (*p != NULL) p = &(*p)->next; |     while (*p != NULL) | ||||||
|  |         p = &(*p)->next; | ||||||
|     *p          = codec; |     *p          = codec; | ||||||
|     codec->next = NULL; |     codec->next = NULL; | ||||||
|  |  | ||||||
| @@ -141,23 +148,24 @@ unsigned avcodec_get_edge_width(void) | |||||||
|     return EDGE_WIDTH; |     return EDGE_WIDTH; | ||||||
| } | } | ||||||
|  |  | ||||||
| void avcodec_set_dimensions(AVCodecContext *s, int width, int height){ | void avcodec_set_dimensions(AVCodecContext *s, int width, int height) | ||||||
|  | { | ||||||
|     s->coded_width  = width; |     s->coded_width  = width; | ||||||
|     s->coded_height= height; |     s->coded_height = height; | ||||||
|     s->width        = width; |     s->width        = width; | ||||||
|     s->height       = height; |     s->height       = height; | ||||||
| } | } | ||||||
|  |  | ||||||
| #define INTERNAL_BUFFER_SIZE (32+1) | #define INTERNAL_BUFFER_SIZE (32 + 1) | ||||||
|  |  | ||||||
| void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height, | void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height, | ||||||
|                                int linesize_align[AV_NUM_DATA_POINTERS]) |                                int linesize_align[AV_NUM_DATA_POINTERS]) | ||||||
| { | { | ||||||
|     int i; |     int i; | ||||||
|     int w_align= 1; |     int w_align = 1; | ||||||
|     int h_align= 1; |     int h_align = 1; | ||||||
|  |  | ||||||
|     switch(s->pix_fmt){ |     switch (s->pix_fmt) { | ||||||
|     case PIX_FMT_YUV420P: |     case PIX_FMT_YUV420P: | ||||||
|     case PIX_FMT_YUYV422: |     case PIX_FMT_YUYV422: | ||||||
|     case PIX_FMT_UYVY422: |     case PIX_FMT_UYVY422: | ||||||
| @@ -194,58 +202,62 @@ void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height, | |||||||
|         break; |         break; | ||||||
|     case PIX_FMT_YUV411P: |     case PIX_FMT_YUV411P: | ||||||
|     case PIX_FMT_UYYVYY411: |     case PIX_FMT_UYYVYY411: | ||||||
|         w_align=32; |         w_align = 32; | ||||||
|         h_align=8; |         h_align = 8; | ||||||
|         break; |         break; | ||||||
|     case PIX_FMT_YUV410P: |     case PIX_FMT_YUV410P: | ||||||
|         if(s->codec_id == AV_CODEC_ID_SVQ1){ |         if (s->codec_id == AV_CODEC_ID_SVQ1) { | ||||||
|             w_align=64; |             w_align = 64; | ||||||
|             h_align=64; |             h_align = 64; | ||||||
|         } |         } | ||||||
|     case PIX_FMT_RGB555: |     case PIX_FMT_RGB555: | ||||||
|         if(s->codec_id == AV_CODEC_ID_RPZA){ |         if (s->codec_id == AV_CODEC_ID_RPZA) { | ||||||
|             w_align=4; |             w_align = 4; | ||||||
|             h_align=4; |             h_align = 4; | ||||||
|         } |         } | ||||||
|     case PIX_FMT_PAL8: |     case PIX_FMT_PAL8: | ||||||
|     case PIX_FMT_BGR8: |     case PIX_FMT_BGR8: | ||||||
|     case PIX_FMT_RGB8: |     case PIX_FMT_RGB8: | ||||||
|         if(s->codec_id == AV_CODEC_ID_SMC){ |         if (s->codec_id == AV_CODEC_ID_SMC) { | ||||||
|             w_align=4; |             w_align = 4; | ||||||
|             h_align=4; |             h_align = 4; | ||||||
|         } |         } | ||||||
|         break; |         break; | ||||||
|     case PIX_FMT_BGR24: |     case PIX_FMT_BGR24: | ||||||
|         if((s->codec_id == AV_CODEC_ID_MSZH) || (s->codec_id == AV_CODEC_ID_ZLIB)){ |         if ((s->codec_id == AV_CODEC_ID_MSZH) || | ||||||
|             w_align=4; |             (s->codec_id == AV_CODEC_ID_ZLIB)) { | ||||||
|             h_align=4; |             w_align = 4; | ||||||
|  |             h_align = 4; | ||||||
|         } |         } | ||||||
|         break; |         break; | ||||||
|     default: |     default: | ||||||
|         w_align= 1; |         w_align = 1; | ||||||
|         h_align= 1; |         h_align = 1; | ||||||
|         break; |         break; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     *width = FFALIGN(*width , w_align); |     *width  = FFALIGN(*width, w_align); | ||||||
|     *height= FFALIGN(*height, h_align); |     *height = FFALIGN(*height, h_align); | ||||||
|     if (s->codec_id == AV_CODEC_ID_H264) |     if (s->codec_id == AV_CODEC_ID_H264) | ||||||
|         *height+=2; // some of the optimized chroma MC reads one line too much |         // some of the optimized chroma MC reads one line too much | ||||||
|  |         *height += 2; | ||||||
|  |  | ||||||
|     for (i = 0; i < 4; i++) |     for (i = 0; i < 4; i++) | ||||||
|         linesize_align[i] = STRIDE_ALIGN; |         linesize_align[i] = STRIDE_ALIGN; | ||||||
| } | } | ||||||
|  |  | ||||||
| void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height){ | void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height) | ||||||
|  | { | ||||||
|     int chroma_shift = av_pix_fmt_descriptors[s->pix_fmt].log2_chroma_w; |     int chroma_shift = av_pix_fmt_descriptors[s->pix_fmt].log2_chroma_w; | ||||||
|     int linesize_align[AV_NUM_DATA_POINTERS]; |     int linesize_align[AV_NUM_DATA_POINTERS]; | ||||||
|     int align; |     int align; | ||||||
|  |  | ||||||
|     avcodec_align_dimensions2(s, width, height, linesize_align); |     avcodec_align_dimensions2(s, width, height, linesize_align); | ||||||
|     align               = FFMAX(linesize_align[0], linesize_align[3]); |     align               = FFMAX(linesize_align[0], linesize_align[3]); | ||||||
|     linesize_align[1] <<= chroma_shift; |     linesize_align[1] <<= chroma_shift; | ||||||
|     linesize_align[2] <<= chroma_shift; |     linesize_align[2] <<= chroma_shift; | ||||||
|     align               = FFMAX3(align, linesize_align[1], linesize_align[2]); |     align               = FFMAX3(align, linesize_align[1], linesize_align[2]); | ||||||
|     *width=FFALIGN(*width, align); |     *width              = FFALIGN(*width, align); | ||||||
| } | } | ||||||
|  |  | ||||||
| int avcodec_fill_audio_frame(AVFrame *frame, int nb_channels, | int avcodec_fill_audio_frame(AVFrame *frame, int nb_channels, | ||||||
| @@ -305,7 +317,7 @@ static int audio_get_buffer(AVCodecContext *avctx, AVFrame *frame) | |||||||
|     buf = avci->buffer; |     buf = avci->buffer; | ||||||
|  |  | ||||||
|     /* if there is a previously-used internal buffer, check its size and |     /* if there is a previously-used internal buffer, check its size and | ||||||
|        channel count to see if we can reuse it */ |      * channel count to see if we can reuse it */ | ||||||
|     if (buf->extended_data) { |     if (buf->extended_data) { | ||||||
|         /* if current buffer is too small, free it */ |         /* if current buffer is too small, free it */ | ||||||
|         if (buf->extended_data[0] && buf_size > buf->audio_data_size) { |         if (buf->extended_data[0] && buf_size > buf->audio_data_size) { | ||||||
| @@ -316,7 +328,7 @@ static int audio_get_buffer(AVCodecContext *avctx, AVFrame *frame) | |||||||
|             buf->data[0]       = NULL; |             buf->data[0]       = NULL; | ||||||
|         } |         } | ||||||
|         /* if number of channels has changed, reset and/or free extended data |         /* if number of channels has changed, reset and/or free extended data | ||||||
|            pointers but leave data buffer in buf->data[0] for reuse */ |          * pointers but leave data buffer in buf->data[0] for reuse */ | ||||||
|         if (buf->nb_channels != avctx->channels) { |         if (buf->nb_channels != avctx->channels) { | ||||||
|             if (buf->extended_data != buf->data) |             if (buf->extended_data != buf->data) | ||||||
|                 av_free(buf->extended_data); |                 av_free(buf->extended_data); | ||||||
| @@ -325,7 +337,7 @@ static int audio_get_buffer(AVCodecContext *avctx, AVFrame *frame) | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /* if there is no previous buffer or the previous buffer cannot be used |     /* if there is no previous buffer or the previous buffer cannot be used | ||||||
|        as-is, allocate a new buffer and/or rearrange the channel pointers */ |      * as-is, allocate a new buffer and/or rearrange the channel pointers */ | ||||||
|     if (!buf->extended_data) { |     if (!buf->extended_data) { | ||||||
|         if (!buf->data[0]) { |         if (!buf->data[0]) { | ||||||
|             if (!(buf->data[0] = av_mallocz(buf_size))) |             if (!(buf->data[0] = av_mallocz(buf_size))) | ||||||
| @@ -353,8 +365,10 @@ static int audio_get_buffer(AVCodecContext *avctx, AVFrame *frame) | |||||||
|  |  | ||||||
|     frame->type = FF_BUFFER_TYPE_INTERNAL; |     frame->type = FF_BUFFER_TYPE_INTERNAL; | ||||||
|  |  | ||||||
|     if (avctx->pkt) frame->pkt_pts = avctx->pkt->pts; |     if (avctx->pkt) | ||||||
|     else            frame->pkt_pts = AV_NOPTS_VALUE; |         frame->pkt_pts = avctx->pkt->pts; | ||||||
|  |     else | ||||||
|  |         frame->pkt_pts = AV_NOPTS_VALUE; | ||||||
|     frame->reordered_opaque = avctx->reordered_opaque; |     frame->reordered_opaque = avctx->reordered_opaque; | ||||||
|  |  | ||||||
|     frame->sample_rate    = avctx->sample_rate; |     frame->sample_rate    = avctx->sample_rate; | ||||||
| @@ -371,53 +385,53 @@ static int audio_get_buffer(AVCodecContext *avctx, AVFrame *frame) | |||||||
| static int video_get_buffer(AVCodecContext *s, AVFrame *pic) | static int video_get_buffer(AVCodecContext *s, AVFrame *pic) | ||||||
| { | { | ||||||
|     int i; |     int i; | ||||||
|     int w= s->width; |     int w = s->width; | ||||||
|     int h= s->height; |     int h = s->height; | ||||||
|     InternalBuffer *buf; |     InternalBuffer *buf; | ||||||
|     AVCodecInternal *avci = s->internal; |     AVCodecInternal *avci = s->internal; | ||||||
|  |  | ||||||
|     if(pic->data[0]!=NULL) { |     if (pic->data[0] != NULL) { | ||||||
|         av_log(s, AV_LOG_ERROR, "pic->data[0]!=NULL in avcodec_default_get_buffer\n"); |         av_log(s, AV_LOG_ERROR, "pic->data[0]!=NULL in avcodec_default_get_buffer\n"); | ||||||
|         return -1; |         return -1; | ||||||
|     } |     } | ||||||
|     if(avci->buffer_count >= INTERNAL_BUFFER_SIZE) { |     if (avci->buffer_count >= INTERNAL_BUFFER_SIZE) { | ||||||
|         av_log(s, AV_LOG_ERROR, "buffer_count overflow (missing release_buffer?)\n"); |         av_log(s, AV_LOG_ERROR, "buffer_count overflow (missing release_buffer?)\n"); | ||||||
|         return -1; |         return -1; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     if(av_image_check_size(w, h, 0, s)) |     if (av_image_check_size(w, h, 0, s)) | ||||||
|         return -1; |         return -1; | ||||||
|  |  | ||||||
|     if (!avci->buffer) { |     if (!avci->buffer) { | ||||||
|         avci->buffer = av_mallocz((INTERNAL_BUFFER_SIZE+1) * |         avci->buffer = av_mallocz((INTERNAL_BUFFER_SIZE + 1) * | ||||||
|                                   sizeof(InternalBuffer)); |                                   sizeof(InternalBuffer)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     buf = &avci->buffer[avci->buffer_count]; |     buf = &avci->buffer[avci->buffer_count]; | ||||||
|  |  | ||||||
|     if(buf->base[0] && (buf->width != w || buf->height != h || buf->pix_fmt != s->pix_fmt)){ |     if (buf->base[0] && (buf->width != w || buf->height != h || buf->pix_fmt != s->pix_fmt)) { | ||||||
|         for (i = 0; i < AV_NUM_DATA_POINTERS; i++) { |         for (i = 0; i < AV_NUM_DATA_POINTERS; i++) { | ||||||
|             av_freep(&buf->base[i]); |             av_freep(&buf->base[i]); | ||||||
|             buf->data[i]= NULL; |             buf->data[i] = NULL; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     if (!buf->base[0]) { |     if (!buf->base[0]) { | ||||||
|         int h_chroma_shift, v_chroma_shift; |         int h_chroma_shift, v_chroma_shift; | ||||||
|         int size[4] = {0}; |         int size[4] = { 0 }; | ||||||
|         int tmpsize; |         int tmpsize; | ||||||
|         int unaligned; |         int unaligned; | ||||||
|         AVPicture picture; |         AVPicture picture; | ||||||
|         int stride_align[AV_NUM_DATA_POINTERS]; |         int stride_align[AV_NUM_DATA_POINTERS]; | ||||||
|         const int pixel_size = av_pix_fmt_descriptors[s->pix_fmt].comp[0].step_minus1+1; |         const int pixel_size = av_pix_fmt_descriptors[s->pix_fmt].comp[0].step_minus1 + 1; | ||||||
|  |  | ||||||
|         avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift); |         avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift); | ||||||
|  |  | ||||||
|         avcodec_align_dimensions2(s, &w, &h, stride_align); |         avcodec_align_dimensions2(s, &w, &h, stride_align); | ||||||
|  |  | ||||||
|         if(!(s->flags&CODEC_FLAG_EMU_EDGE)){ |         if (!(s->flags & CODEC_FLAG_EMU_EDGE)) { | ||||||
|             w+= EDGE_WIDTH*2; |             w += EDGE_WIDTH * 2; | ||||||
|             h+= EDGE_WIDTH*2; |             h += EDGE_WIDTH * 2; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         do { |         do { | ||||||
| @@ -425,57 +439,57 @@ static int video_get_buffer(AVCodecContext *s, AVFrame *pic) | |||||||
|             // that linesize[0] == 2*linesize[1] in the MPEG-encoder for 4:2:2 |             // that linesize[0] == 2*linesize[1] in the MPEG-encoder for 4:2:2 | ||||||
|             av_image_fill_linesizes(picture.linesize, s->pix_fmt, w); |             av_image_fill_linesizes(picture.linesize, s->pix_fmt, w); | ||||||
|             // increase alignment of w for next try (rhs gives the lowest bit set in w) |             // increase alignment of w for next try (rhs gives the lowest bit set in w) | ||||||
|             w += w & ~(w-1); |             w += w & ~(w - 1); | ||||||
|  |  | ||||||
|             unaligned = 0; |             unaligned = 0; | ||||||
|             for (i=0; i<4; i++){ |             for (i = 0; i < 4; i++) | ||||||
|                 unaligned |= picture.linesize[i] % stride_align[i]; |                 unaligned |= picture.linesize[i] % stride_align[i]; | ||||||
|             } |  | ||||||
|         } while (unaligned); |         } while (unaligned); | ||||||
|  |  | ||||||
|         tmpsize = av_image_fill_pointers(picture.data, s->pix_fmt, h, NULL, picture.linesize); |         tmpsize = av_image_fill_pointers(picture.data, s->pix_fmt, h, NULL, picture.linesize); | ||||||
|         if (tmpsize < 0) |         if (tmpsize < 0) | ||||||
|             return -1; |             return -1; | ||||||
|  |  | ||||||
|         for (i=0; i<3 && picture.data[i+1]; i++) |         for (i = 0; i < 3 && picture.data[i + 1]; i++) | ||||||
|             size[i] = picture.data[i+1] - picture.data[i]; |             size[i] = picture.data[i + 1] - picture.data[i]; | ||||||
|         size[i] = tmpsize - (picture.data[i] - picture.data[0]); |         size[i] = tmpsize - (picture.data[i] - picture.data[0]); | ||||||
|  |  | ||||||
|         memset(buf->base, 0, sizeof(buf->base)); |         memset(buf->base, 0, sizeof(buf->base)); | ||||||
|         memset(buf->data, 0, sizeof(buf->data)); |         memset(buf->data, 0, sizeof(buf->data)); | ||||||
|  |  | ||||||
|         for(i=0; i<4 && size[i]; i++){ |         for (i = 0; i < 4 && size[i]; i++) { | ||||||
|             const int h_shift= i==0 ? 0 : h_chroma_shift; |             const int h_shift = i == 0 ? 0 : h_chroma_shift; | ||||||
|             const int v_shift= i==0 ? 0 : v_chroma_shift; |             const int v_shift = i == 0 ? 0 : v_chroma_shift; | ||||||
|  |  | ||||||
|             buf->linesize[i]= picture.linesize[i]; |             buf->linesize[i] = picture.linesize[i]; | ||||||
|  |  | ||||||
|             buf->base[i]= av_malloc(size[i]+16); //FIXME 16 |             buf->base[i] = av_malloc(size[i] + 16); //FIXME 16 | ||||||
|             if(buf->base[i]==NULL) return -1; |             if (buf->base[i] == NULL) | ||||||
|  |                 return -1; | ||||||
|             memset(buf->base[i], 128, size[i]); |             memset(buf->base[i], 128, size[i]); | ||||||
|  |  | ||||||
|             // no edge if EDGE EMU or not planar YUV |             // no edge if EDGE EMU or not planar YUV | ||||||
|             if((s->flags&CODEC_FLAG_EMU_EDGE) || !size[2]) |             if ((s->flags & CODEC_FLAG_EMU_EDGE) || !size[2]) | ||||||
|                 buf->data[i] = buf->base[i]; |                 buf->data[i] = buf->base[i]; | ||||||
|             else |             else | ||||||
|                 buf->data[i] = buf->base[i] + FFALIGN((buf->linesize[i]*EDGE_WIDTH>>v_shift) + (pixel_size*EDGE_WIDTH>>h_shift), stride_align[i]); |                 buf->data[i] = buf->base[i] + FFALIGN((buf->linesize[i] * EDGE_WIDTH >> v_shift) + (pixel_size * EDGE_WIDTH >> h_shift), stride_align[i]); | ||||||
|         } |         } | ||||||
|         for (; i < AV_NUM_DATA_POINTERS; i++) { |         for (; i < AV_NUM_DATA_POINTERS; i++) { | ||||||
|             buf->base[i]     = buf->data[i] = NULL; |             buf->base[i]     = buf->data[i] = NULL; | ||||||
|             buf->linesize[i] = 0; |             buf->linesize[i] = 0; | ||||||
|         } |         } | ||||||
|         if(size[1] && !size[2]) |         if (size[1] && !size[2]) | ||||||
|             ff_set_systematic_pal2((uint32_t*)buf->data[1], s->pix_fmt); |             ff_set_systematic_pal2((uint32_t *)buf->data[1], s->pix_fmt); | ||||||
|         buf->width   = s->width; |         buf->width   = s->width; | ||||||
|         buf->height  = s->height; |         buf->height  = s->height; | ||||||
|         buf->pix_fmt= s->pix_fmt; |         buf->pix_fmt = s->pix_fmt; | ||||||
|     } |     } | ||||||
|     pic->type= FF_BUFFER_TYPE_INTERNAL; |     pic->type = FF_BUFFER_TYPE_INTERNAL; | ||||||
|  |  | ||||||
|     for (i = 0; i < AV_NUM_DATA_POINTERS; i++) { |     for (i = 0; i < AV_NUM_DATA_POINTERS; i++) { | ||||||
|         pic->base[i]= buf->base[i]; |         pic->base[i]     = buf->base[i]; | ||||||
|         pic->data[i]= buf->data[i]; |         pic->data[i]     = buf->data[i]; | ||||||
|         pic->linesize[i]= buf->linesize[i]; |         pic->linesize[i] = buf->linesize[i]; | ||||||
|     } |     } | ||||||
|     pic->extended_data = pic->data; |     pic->extended_data = pic->data; | ||||||
|     avci->buffer_count++; |     avci->buffer_count++; | ||||||
| @@ -484,11 +498,13 @@ static int video_get_buffer(AVCodecContext *s, AVFrame *pic) | |||||||
|     pic->format              = buf->pix_fmt; |     pic->format              = buf->pix_fmt; | ||||||
|     pic->sample_aspect_ratio = s->sample_aspect_ratio; |     pic->sample_aspect_ratio = s->sample_aspect_ratio; | ||||||
|  |  | ||||||
|     if(s->pkt) pic->pkt_pts= s->pkt->pts; |     if (s->pkt) | ||||||
|     else       pic->pkt_pts= AV_NOPTS_VALUE; |         pic->pkt_pts = s->pkt->pts; | ||||||
|     pic->reordered_opaque= s->reordered_opaque; |     else | ||||||
|  |         pic->pkt_pts = AV_NOPTS_VALUE; | ||||||
|  |     pic->reordered_opaque = s->reordered_opaque; | ||||||
|  |  | ||||||
|     if(s->debug&FF_DEBUG_BUFFERS) |     if (s->debug & FF_DEBUG_BUFFERS) | ||||||
|         av_log(s, AV_LOG_DEBUG, "default_get_buffer called on pic %p, %d " |         av_log(s, AV_LOG_DEBUG, "default_get_buffer called on pic %p, %d " | ||||||
|                                 "buffers used\n", pic, avci->buffer_count); |                                 "buffers used\n", pic, avci->buffer_count); | ||||||
|  |  | ||||||
| @@ -507,14 +523,15 @@ int avcodec_default_get_buffer(AVCodecContext *avctx, AVFrame *frame) | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){ | void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic) | ||||||
|  | { | ||||||
|     int i; |     int i; | ||||||
|     InternalBuffer *buf, *last; |     InternalBuffer *buf, *last; | ||||||
|     AVCodecInternal *avci = s->internal; |     AVCodecInternal *avci = s->internal; | ||||||
|  |  | ||||||
|     assert(s->codec_type == AVMEDIA_TYPE_VIDEO); |     assert(s->codec_type == AVMEDIA_TYPE_VIDEO); | ||||||
|  |  | ||||||
|     assert(pic->type==FF_BUFFER_TYPE_INTERNAL); |     assert(pic->type == FF_BUFFER_TYPE_INTERNAL); | ||||||
|     assert(avci->buffer_count); |     assert(avci->buffer_count); | ||||||
|  |  | ||||||
|     if (avci->buffer) { |     if (avci->buffer) { | ||||||
| @@ -532,25 +549,25 @@ void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){ | |||||||
|             FFSWAP(InternalBuffer, *buf, *last); |             FFSWAP(InternalBuffer, *buf, *last); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     for (i = 0; i < AV_NUM_DATA_POINTERS; i++) { |     for (i = 0; i < AV_NUM_DATA_POINTERS; i++) | ||||||
|         pic->data[i]=NULL; |         pic->data[i] = NULL; | ||||||
| //        pic->base[i]=NULL; | //        pic->base[i]=NULL; | ||||||
|     } |      //printf("R%X\n", pic->opaque); | ||||||
| //printf("R%X\n", pic->opaque); |  | ||||||
|  |  | ||||||
|     if(s->debug&FF_DEBUG_BUFFERS) |     if (s->debug & FF_DEBUG_BUFFERS) | ||||||
|         av_log(s, AV_LOG_DEBUG, "default_release_buffer called on pic %p, %d " |         av_log(s, AV_LOG_DEBUG, "default_release_buffer called on pic %p, %d " | ||||||
|                                 "buffers used\n", pic, avci->buffer_count); |                                 "buffers used\n", pic, avci->buffer_count); | ||||||
| } | } | ||||||
|  |  | ||||||
| int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic){ | int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic) | ||||||
|  | { | ||||||
|     AVFrame temp_pic; |     AVFrame temp_pic; | ||||||
|     int i; |     int i; | ||||||
|  |  | ||||||
|     assert(s->codec_type == AVMEDIA_TYPE_VIDEO); |     assert(s->codec_type == AVMEDIA_TYPE_VIDEO); | ||||||
|  |  | ||||||
|     /* If no picture return a new buffer */ |     /* If no picture return a new buffer */ | ||||||
|     if(pic->data[0] == NULL) { |     if (pic->data[0] == NULL) { | ||||||
|         /* We will copy from buffer, so must be readable */ |         /* We will copy from buffer, so must be readable */ | ||||||
|         pic->buffer_hints |= FF_BUFFER_HINTS_READABLE; |         pic->buffer_hints |= FF_BUFFER_HINTS_READABLE; | ||||||
|         return s->get_buffer(s, pic); |         return s->get_buffer(s, pic); | ||||||
| @@ -559,10 +576,12 @@ int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic){ | |||||||
|     assert(s->pix_fmt == pic->format); |     assert(s->pix_fmt == pic->format); | ||||||
|  |  | ||||||
|     /* If internal buffer type return the same buffer */ |     /* If internal buffer type return the same buffer */ | ||||||
|     if(pic->type == FF_BUFFER_TYPE_INTERNAL) { |     if (pic->type == FF_BUFFER_TYPE_INTERNAL) { | ||||||
|         if(s->pkt) pic->pkt_pts= s->pkt->pts; |         if (s->pkt) | ||||||
|         else       pic->pkt_pts= AV_NOPTS_VALUE; |             pic->pkt_pts = s->pkt->pts; | ||||||
|         pic->reordered_opaque= s->reordered_opaque; |         else | ||||||
|  |             pic->pkt_pts = AV_NOPTS_VALUE; | ||||||
|  |         pic->reordered_opaque = s->reordered_opaque; | ||||||
|         return 0; |         return 0; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -570,58 +589,66 @@ int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic){ | |||||||
|      * Not internal type and reget_buffer not overridden, emulate cr buffer |      * Not internal type and reget_buffer not overridden, emulate cr buffer | ||||||
|      */ |      */ | ||||||
|     temp_pic = *pic; |     temp_pic = *pic; | ||||||
|     for(i = 0; i < AV_NUM_DATA_POINTERS; i++) |     for (i = 0; i < AV_NUM_DATA_POINTERS; i++) | ||||||
|         pic->data[i] = pic->base[i] = NULL; |         pic->data[i] = pic->base[i] = NULL; | ||||||
|     pic->opaque = NULL; |     pic->opaque = NULL; | ||||||
|     /* Allocate new frame */ |     /* Allocate new frame */ | ||||||
|     if (s->get_buffer(s, pic)) |     if (s->get_buffer(s, pic)) | ||||||
|         return -1; |         return -1; | ||||||
|     /* Copy image data from old buffer to new buffer */ |     /* Copy image data from old buffer to new buffer */ | ||||||
|     av_picture_copy((AVPicture*)pic, (AVPicture*)&temp_pic, s->pix_fmt, s->width, |     av_picture_copy((AVPicture *)pic, (AVPicture *)&temp_pic, s->pix_fmt, s->width, | ||||||
|                     s->height); |                     s->height); | ||||||
|     s->release_buffer(s, &temp_pic); // Release old frame |     s->release_buffer(s, &temp_pic); // Release old frame | ||||||
|     return 0; |     return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size){ | int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2), void *arg, int *ret, int count, int size) | ||||||
|  | { | ||||||
|     int i; |     int i; | ||||||
|  |  | ||||||
|     for(i=0; i<count; i++){ |     for (i = 0; i < count; i++) { | ||||||
|         int r= func(c, (char*)arg + i*size); |         int r = func(c, (char *)arg + i * size); | ||||||
|         if(ret) ret[i]= r; |         if (ret) | ||||||
|  |             ret[i] = r; | ||||||
|     } |     } | ||||||
|     return 0; |     return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int jobnr, int threadnr),void *arg, int *ret, int count){ | int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int jobnr, int threadnr), void *arg, int *ret, int count) | ||||||
|  | { | ||||||
|     int i; |     int i; | ||||||
|  |  | ||||||
|     for(i=0; i<count; i++){ |     for (i = 0; i < count; i++) { | ||||||
|         int r= func(c, arg, i, 0); |         int r = func(c, arg, i, 0); | ||||||
|         if(ret) ret[i]= r; |         if (ret) | ||||||
|  |             ret[i] = r; | ||||||
|     } |     } | ||||||
|     return 0; |     return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat *fmt){ | enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat *fmt) | ||||||
|  | { | ||||||
|     while (*fmt != PIX_FMT_NONE && ff_is_hwaccel_pix_fmt(*fmt)) |     while (*fmt != PIX_FMT_NONE && ff_is_hwaccel_pix_fmt(*fmt)) | ||||||
|         ++fmt; |         ++fmt; | ||||||
|     return fmt[0]; |     return fmt[0]; | ||||||
| } | } | ||||||
|  |  | ||||||
| void avcodec_get_frame_defaults(AVFrame *pic){ | void avcodec_get_frame_defaults(AVFrame *pic) | ||||||
|  | { | ||||||
|     memset(pic, 0, sizeof(AVFrame)); |     memset(pic, 0, sizeof(AVFrame)); | ||||||
|  |  | ||||||
|     pic->pts= AV_NOPTS_VALUE; |     pic->pts                 = AV_NOPTS_VALUE; | ||||||
|     pic->key_frame= 1; |     pic->key_frame           = 1; | ||||||
|     pic->sample_aspect_ratio = (AVRational){0, 1}; |     pic->sample_aspect_ratio = (AVRational) {0, 1 }; | ||||||
|     pic->format              = -1; /* unknown */ |     pic->format              = -1; /* unknown */ | ||||||
| } | } | ||||||
|  |  | ||||||
| AVFrame *avcodec_alloc_frame(void){ | AVFrame *avcodec_alloc_frame(void) | ||||||
|     AVFrame *pic= av_malloc(sizeof(AVFrame)); | { | ||||||
|  |     AVFrame *pic = av_malloc(sizeof(AVFrame)); | ||||||
|  |  | ||||||
|     if(pic==NULL) return NULL; |     if (pic == NULL) | ||||||
|  |         return NULL; | ||||||
|  |  | ||||||
|     avcodec_get_frame_defaults(pic); |     avcodec_get_frame_defaults(pic); | ||||||
|  |  | ||||||
| @@ -661,7 +688,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     entangled_thread_counter++; |     entangled_thread_counter++; | ||||||
|     if(entangled_thread_counter != 1){ |     if (entangled_thread_counter != 1) { | ||||||
|         av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n"); |         av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n"); | ||||||
|         ret = -1; |         ret = -1; | ||||||
|         goto end; |         goto end; | ||||||
| @@ -674,14 +701,14 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     if (codec->priv_data_size > 0) { |     if (codec->priv_data_size > 0) { | ||||||
|       if(!avctx->priv_data){ |         if (!avctx->priv_data) { | ||||||
|             avctx->priv_data = av_mallocz(codec->priv_data_size); |             avctx->priv_data = av_mallocz(codec->priv_data_size); | ||||||
|             if (!avctx->priv_data) { |             if (!avctx->priv_data) { | ||||||
|                 ret = AVERROR(ENOMEM); |                 ret = AVERROR(ENOMEM); | ||||||
|                 goto end; |                 goto end; | ||||||
|             } |             } | ||||||
|             if (codec->priv_class) { |             if (codec->priv_class) { | ||||||
|             *(const AVClass**)avctx->priv_data = codec->priv_class; |                 *(const AVClass **)avctx->priv_data = codec->priv_class; | ||||||
|                 av_opt_set_defaults(avctx->priv_data); |                 av_opt_set_defaults(avctx->priv_data); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| @@ -693,9 +720,9 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code | |||||||
|     if ((ret = av_opt_set_dict(avctx, &tmp)) < 0) |     if ((ret = av_opt_set_dict(avctx, &tmp)) < 0) | ||||||
|         goto free_and_end; |         goto free_and_end; | ||||||
|  |  | ||||||
|     if(avctx->coded_width && avctx->coded_height) |     if (avctx->coded_width && avctx->coded_height) | ||||||
|         avcodec_set_dimensions(avctx, avctx->coded_width, avctx->coded_height); |         avcodec_set_dimensions(avctx, avctx->coded_width, avctx->coded_height); | ||||||
|     else if(avctx->width && avctx->height) |     else if (avctx->width && avctx->height) | ||||||
|         avcodec_set_dimensions(avctx, avctx->width, avctx->height); |         avcodec_set_dimensions(avctx, avctx->width, avctx->height); | ||||||
|  |  | ||||||
|     if ((avctx->coded_width || avctx->coded_height || avctx->width || avctx->height) |     if ((avctx->coded_width || avctx->coded_height || avctx->width || avctx->height) | ||||||
| @@ -706,7 +733,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /* if the decoder init function was already called previously, |     /* if the decoder init function was already called previously, | ||||||
|        free the already allocated subtitle_header before overwriting it */ |      * free the already allocated subtitle_header before overwriting it */ | ||||||
|     if (av_codec_is_decoder(codec)) |     if (av_codec_is_decoder(codec)) | ||||||
|         av_freep(&avctx->subtitle_header); |         av_freep(&avctx->subtitle_header); | ||||||
|  |  | ||||||
| @@ -802,7 +829,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     if(avctx->codec->init && !(avctx->active_thread_type&FF_THREAD_FRAME)){ |     if (avctx->codec->init && !(avctx->active_thread_type & FF_THREAD_FRAME)) { | ||||||
|         ret = avctx->codec->init(avctx); |         ret = avctx->codec->init(avctx); | ||||||
|         if (ret < 0) { |         if (ret < 0) { | ||||||
|             goto free_and_end; |             goto free_and_end; | ||||||
| @@ -834,7 +861,7 @@ free_and_end: | |||||||
|     av_dict_free(&tmp); |     av_dict_free(&tmp); | ||||||
|     av_freep(&avctx->priv_data); |     av_freep(&avctx->priv_data); | ||||||
|     av_freep(&avctx->internal); |     av_freep(&avctx->internal); | ||||||
|     avctx->codec= NULL; |     avctx->codec = NULL; | ||||||
|     goto end; |     goto end; | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -990,8 +1017,8 @@ int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx, | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /* NOTE: if we add any audio encoders which output non-keyframe packets, |     /* NOTE: if we add any audio encoders which output non-keyframe packets, | ||||||
|              this needs to be moved to the encoders, but for now we can do it |      *       this needs to be moved to the encoders, but for now we can do it | ||||||
|              here to simplify things */ |      *       here to simplify things */ | ||||||
|     avpkt->flags |= AV_PKT_FLAG_KEY; |     avpkt->flags |= AV_PKT_FLAG_KEY; | ||||||
|  |  | ||||||
|     if (padded_frame) { |     if (padded_frame) { | ||||||
| @@ -1026,7 +1053,7 @@ int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx, | |||||||
|             frame->nb_samples = avctx->frame_size; |             frame->nb_samples = avctx->frame_size; | ||||||
|         } else { |         } else { | ||||||
|             /* if frame_size is not set, the number of samples must be |             /* if frame_size is not set, the number of samples must be | ||||||
|                calculated from the buffer size */ |              * calculated from the buffer size */ | ||||||
|             int64_t nb_samples; |             int64_t nb_samples; | ||||||
|             if (!av_get_bits_per_sample(avctx->codec_id)) { |             if (!av_get_bits_per_sample(avctx->codec_id)) { | ||||||
|                 av_log(avctx, AV_LOG_ERROR, "avcodec_encode_audio() does not " |                 av_log(avctx, AV_LOG_ERROR, "avcodec_encode_audio() does not " | ||||||
| @@ -1042,19 +1069,19 @@ int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx, | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         /* it is assumed that the samples buffer is large enough based on the |         /* it is assumed that the samples buffer is large enough based on the | ||||||
|            relevant parameters */ |          * relevant parameters */ | ||||||
|         samples_size = av_samples_get_buffer_size(NULL, avctx->channels, |         samples_size = av_samples_get_buffer_size(NULL, avctx->channels, | ||||||
|                                                   frame->nb_samples, |                                                   frame->nb_samples, | ||||||
|                                                   avctx->sample_fmt, 1); |                                                   avctx->sample_fmt, 1); | ||||||
|         if ((ret = avcodec_fill_audio_frame(frame, avctx->channels, |         if ((ret = avcodec_fill_audio_frame(frame, avctx->channels, | ||||||
|                                             avctx->sample_fmt, |                                             avctx->sample_fmt, | ||||||
|                                             (const uint8_t *) samples, |                                             (const uint8_t *)samples, | ||||||
|                                             samples_size, 1))) |                                             samples_size, 1))) | ||||||
|             return ret; |             return ret; | ||||||
|  |  | ||||||
|         /* fabricate frame pts from sample count. |         /* fabricate frame pts from sample count. | ||||||
|            this is needed because the avcodec_encode_audio() API does not have |          * this is needed because the avcodec_encode_audio() API does not have | ||||||
|            a way for the user to provide pts */ |          * a way for the user to provide pts */ | ||||||
|         frame->pts = ff_samples_to_time_base(avctx, |         frame->pts = ff_samples_to_time_base(avctx, | ||||||
|                                              avctx->internal->sample_count); |                                              avctx->internal->sample_count); | ||||||
|         avctx->internal->sample_count += frame->nb_samples; |         avctx->internal->sample_count += frame->nb_samples; | ||||||
| @@ -1082,6 +1109,7 @@ int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx, | |||||||
|  |  | ||||||
|     return ret ? ret : pkt.size; |     return ret ? ret : pkt.size; | ||||||
| } | } | ||||||
|  |  | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| #if FF_API_OLD_ENCODE_VIDEO | #if FF_API_OLD_ENCODE_VIDEO | ||||||
| @@ -1091,7 +1119,7 @@ int attribute_align_arg avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf | |||||||
|     AVPacket pkt; |     AVPacket pkt; | ||||||
|     int ret, got_packet = 0; |     int ret, got_packet = 0; | ||||||
|  |  | ||||||
|     if(buf_size < FF_MIN_BUFFER_SIZE){ |     if (buf_size < FF_MIN_BUFFER_SIZE) { | ||||||
|         av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n"); |         av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n"); | ||||||
|         return -1; |         return -1; | ||||||
|     } |     } | ||||||
| @@ -1117,6 +1145,7 @@ int attribute_align_arg avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf | |||||||
|  |  | ||||||
|     return ret ? ret : pkt.size; |     return ret ? ret : pkt.size; | ||||||
| } | } | ||||||
|  |  | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx, | int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx, | ||||||
| @@ -1168,11 +1197,11 @@ int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size, | |||||||
|                             const AVSubtitle *sub) |                             const AVSubtitle *sub) | ||||||
| { | { | ||||||
|     int ret; |     int ret; | ||||||
|     if(sub->start_display_time) { |     if (sub->start_display_time) { | ||||||
|         av_log(avctx, AV_LOG_ERROR, "start_display_time must be 0.\n"); |         av_log(avctx, AV_LOG_ERROR, "start_display_time must be 0.\n"); | ||||||
|         return -1; |         return -1; | ||||||
|     } |     } | ||||||
|     if(sub->num_rects == 0 || !sub->rects) |     if (sub->num_rects == 0 || !sub->rects) | ||||||
|         return -1; |         return -1; | ||||||
|     ret = avctx->codec->encode_sub(avctx, buf, buf_size, sub); |     ret = avctx->codec->encode_sub(avctx, buf, buf_size, sub); | ||||||
|     avctx->frame_number++; |     avctx->frame_number++; | ||||||
| @@ -1227,21 +1256,21 @@ int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *pi | |||||||
| { | { | ||||||
|     int ret; |     int ret; | ||||||
|  |  | ||||||
|     *got_picture_ptr= 0; |     *got_picture_ptr = 0; | ||||||
|     if((avctx->coded_width||avctx->coded_height) && av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx)) |     if ((avctx->coded_width || avctx->coded_height) && av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx)) | ||||||
|         return -1; |         return -1; | ||||||
|  |  | ||||||
|     avctx->pkt = avpkt; |     avctx->pkt = avpkt; | ||||||
|     apply_param_change(avctx, avpkt); |     apply_param_change(avctx, avpkt); | ||||||
|  |  | ||||||
|     if((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size || (avctx->active_thread_type&FF_THREAD_FRAME)){ |     if ((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size || (avctx->active_thread_type & FF_THREAD_FRAME)) { | ||||||
|         if (HAVE_THREADS && avctx->active_thread_type&FF_THREAD_FRAME) |         if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME) | ||||||
|             ret = ff_thread_decode_frame(avctx, picture, got_picture_ptr, |             ret = ff_thread_decode_frame(avctx, picture, got_picture_ptr, | ||||||
|                                          avpkt); |                                          avpkt); | ||||||
|         else { |         else { | ||||||
|             ret = avctx->codec->decode(avctx, picture, got_picture_ptr, |             ret = avctx->codec->decode(avctx, picture, got_picture_ptr, | ||||||
|                                        avpkt); |                                        avpkt); | ||||||
|             picture->pkt_dts= avpkt->dts; |             picture->pkt_dts             = avpkt->dts; | ||||||
|             picture->sample_aspect_ratio = avctx->sample_aspect_ratio; |             picture->sample_aspect_ratio = avctx->sample_aspect_ratio; | ||||||
|             picture->width               = avctx->width; |             picture->width               = avctx->width; | ||||||
|             picture->height              = avctx->height; |             picture->height              = avctx->height; | ||||||
| @@ -1252,8 +1281,8 @@ int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *pi | |||||||
|  |  | ||||||
|         if (*got_picture_ptr) |         if (*got_picture_ptr) | ||||||
|             avctx->frame_number++; |             avctx->frame_number++; | ||||||
|     }else |     } else | ||||||
|         ret= 0; |         ret = 0; | ||||||
|  |  | ||||||
|     return ret; |     return ret; | ||||||
| } | } | ||||||
| @@ -1303,6 +1332,7 @@ int attribute_align_arg avcodec_decode_audio3(AVCodecContext *avctx, int16_t *sa | |||||||
|     } |     } | ||||||
|     return ret; |     return ret; | ||||||
| } | } | ||||||
|  |  | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx, | int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx, | ||||||
| @@ -1353,8 +1383,7 @@ void avsubtitle_free(AVSubtitle *sub) | |||||||
| { | { | ||||||
|     int i; |     int i; | ||||||
|  |  | ||||||
|     for (i = 0; i < sub->num_rects; i++) |     for (i = 0; i < sub->num_rects; i++) { | ||||||
|     { |  | ||||||
|         av_freep(&sub->rects[i]->pict.data[0]); |         av_freep(&sub->rects[i]->pict.data[0]); | ||||||
|         av_freep(&sub->rects[i]->pict.data[1]); |         av_freep(&sub->rects[i]->pict.data[1]); | ||||||
|         av_freep(&sub->rects[i]->pict.data[2]); |         av_freep(&sub->rects[i]->pict.data[2]); | ||||||
| @@ -1378,7 +1407,7 @@ av_cold int avcodec_close(AVCodecContext *avctx) | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     entangled_thread_counter++; |     entangled_thread_counter++; | ||||||
|     if(entangled_thread_counter != 1){ |     if (entangled_thread_counter != 1) { | ||||||
|         av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n"); |         av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n"); | ||||||
|         entangled_thread_counter--; |         entangled_thread_counter--; | ||||||
|         return -1; |         return -1; | ||||||
| @@ -1413,7 +1442,7 @@ av_cold int avcodec_close(AVCodecContext *avctx) | |||||||
|  |  | ||||||
| AVCodec *avcodec_find_encoder(enum AVCodecID id) | AVCodec *avcodec_find_encoder(enum AVCodecID id) | ||||||
| { | { | ||||||
|     AVCodec *p, *experimental=NULL; |     AVCodec *p, *experimental = NULL; | ||||||
|     p = first_avcodec; |     p = first_avcodec; | ||||||
|     while (p) { |     while (p) { | ||||||
|         if (av_codec_is_encoder(p) && p->id == id) { |         if (av_codec_is_encoder(p) && p->id == id) { | ||||||
| @@ -1434,7 +1463,7 @@ AVCodec *avcodec_find_encoder_by_name(const char *name) | |||||||
|         return NULL; |         return NULL; | ||||||
|     p = first_avcodec; |     p = first_avcodec; | ||||||
|     while (p) { |     while (p) { | ||||||
|         if (av_codec_is_encoder(p) && strcmp(name,p->name) == 0) |         if (av_codec_is_encoder(p) && strcmp(name, p->name) == 0) | ||||||
|             return p; |             return p; | ||||||
|         p = p->next; |         p = p->next; | ||||||
|     } |     } | ||||||
| @@ -1460,7 +1489,7 @@ AVCodec *avcodec_find_decoder_by_name(const char *name) | |||||||
|         return NULL; |         return NULL; | ||||||
|     p = first_avcodec; |     p = first_avcodec; | ||||||
|     while (p) { |     while (p) { | ||||||
|         if (av_codec_is_decoder(p) && strcmp(name,p->name) == 0) |         if (av_codec_is_decoder(p) && strcmp(name, p->name) == 0) | ||||||
|             return p; |             return p; | ||||||
|         p = p->next; |         p = p->next; | ||||||
|     } |     } | ||||||
| @@ -1472,7 +1501,7 @@ static int get_bit_rate(AVCodecContext *ctx) | |||||||
|     int bit_rate; |     int bit_rate; | ||||||
|     int bits_per_sample; |     int bits_per_sample; | ||||||
|  |  | ||||||
|     switch(ctx->codec_type) { |     switch (ctx->codec_type) { | ||||||
|     case AVMEDIA_TYPE_VIDEO: |     case AVMEDIA_TYPE_VIDEO: | ||||||
|     case AVMEDIA_TYPE_DATA: |     case AVMEDIA_TYPE_DATA: | ||||||
|     case AVMEDIA_TYPE_SUBTITLE: |     case AVMEDIA_TYPE_SUBTITLE: | ||||||
| @@ -1496,11 +1525,11 @@ size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_ta | |||||||
|  |  | ||||||
|     for (i = 0; i < 4; i++) { |     for (i = 0; i < 4; i++) { | ||||||
|         len = snprintf(buf, buf_size, |         len = snprintf(buf, buf_size, | ||||||
|                        isprint(codec_tag&0xFF) ? "%c" : "[%d]", codec_tag&0xFF); |                        isprint(codec_tag & 0xFF) ? "%c" : "[%d]", codec_tag & 0xFF); | ||||||
|         buf        += len; |         buf        += len; | ||||||
|         buf_size    = buf_size > len ? buf_size - len : 0; |         buf_size    = buf_size > len ? buf_size - len : 0; | ||||||
|         ret        += len; |         ret        += len; | ||||||
|         codec_tag>>=8; |         codec_tag >>= 8; | ||||||
|     } |     } | ||||||
|     return ret; |     return ret; | ||||||
| } | } | ||||||
| @@ -1526,7 +1555,7 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode) | |||||||
|         profile = av_get_profile_name(p, enc->profile); |         profile = av_get_profile_name(p, enc->profile); | ||||||
|     } else if (enc->codec_id == AV_CODEC_ID_MPEG2TS) { |     } else if (enc->codec_id == AV_CODEC_ID_MPEG2TS) { | ||||||
|         /* fake mpeg2 transport stream codec (currently not |         /* fake mpeg2 transport stream codec (currently not | ||||||
|            registered) */ |          * registered) */ | ||||||
|         codec_name = "mpeg2ts"; |         codec_name = "mpeg2ts"; | ||||||
|     } else if (enc->codec_name[0] != '\0') { |     } else if (enc->codec_name[0] != '\0') { | ||||||
|         codec_name = enc->codec_name; |         codec_name = enc->codec_name; | ||||||
| @@ -1538,7 +1567,7 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode) | |||||||
|         codec_name = buf1; |         codec_name = buf1; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     switch(enc->codec_type) { |     switch (enc->codec_type) { | ||||||
|     case AVMEDIA_TYPE_VIDEO: |     case AVMEDIA_TYPE_VIDEO: | ||||||
|         snprintf(buf, buf_size, |         snprintf(buf, buf_size, | ||||||
|                  "Video: %s%s", |                  "Video: %s%s", | ||||||
| @@ -1557,19 +1586,19 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode) | |||||||
|                      enc->width, enc->height); |                      enc->width, enc->height); | ||||||
|             if (enc->sample_aspect_ratio.num) { |             if (enc->sample_aspect_ratio.num) { | ||||||
|                 av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den, |                 av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den, | ||||||
|                           enc->width*enc->sample_aspect_ratio.num, |                           enc->width * enc->sample_aspect_ratio.num, | ||||||
|                           enc->height*enc->sample_aspect_ratio.den, |                           enc->height * enc->sample_aspect_ratio.den, | ||||||
|                           1024*1024); |                           1024 * 1024); | ||||||
|                 snprintf(buf + strlen(buf), buf_size - strlen(buf), |                 snprintf(buf + strlen(buf), buf_size - strlen(buf), | ||||||
|                          " [PAR %d:%d DAR %d:%d]", |                          " [PAR %d:%d DAR %d:%d]", | ||||||
|                          enc->sample_aspect_ratio.num, enc->sample_aspect_ratio.den, |                          enc->sample_aspect_ratio.num, enc->sample_aspect_ratio.den, | ||||||
|                          display_aspect_ratio.num, display_aspect_ratio.den); |                          display_aspect_ratio.num, display_aspect_ratio.den); | ||||||
|             } |             } | ||||||
|             if(av_log_get_level() >= AV_LOG_DEBUG){ |             if (av_log_get_level() >= AV_LOG_DEBUG) { | ||||||
|                 int g= av_gcd(enc->time_base.num, enc->time_base.den); |                 int g = av_gcd(enc->time_base.num, enc->time_base.den); | ||||||
|                 snprintf(buf + strlen(buf), buf_size - strlen(buf), |                 snprintf(buf + strlen(buf), buf_size - strlen(buf), | ||||||
|                          ", %d/%d", |                          ", %d/%d", | ||||||
|                      enc->time_base.num/g, enc->time_base.den/g); |                          enc->time_base.num / g, enc->time_base.den / g); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         if (encode) { |         if (encode) { | ||||||
| @@ -1636,7 +1665,7 @@ const char *av_get_profile_name(const AVCodec *codec, int profile) | |||||||
|     return NULL; |     return NULL; | ||||||
| } | } | ||||||
|  |  | ||||||
| unsigned avcodec_version( void ) | unsigned avcodec_version(void) | ||||||
| { | { | ||||||
|     return LIBAVCODEC_VERSION_INT; |     return LIBAVCODEC_VERSION_INT; | ||||||
| } | } | ||||||
| @@ -1654,9 +1683,9 @@ const char *avcodec_license(void) | |||||||
|  |  | ||||||
| void avcodec_flush_buffers(AVCodecContext *avctx) | void avcodec_flush_buffers(AVCodecContext *avctx) | ||||||
| { | { | ||||||
|     if(HAVE_THREADS && avctx->active_thread_type&FF_THREAD_FRAME) |     if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME) | ||||||
|         ff_thread_flush(avctx); |         ff_thread_flush(avctx); | ||||||
|     else if(avctx->codec->flush) |     else if (avctx->codec->flush) | ||||||
|         avctx->codec->flush(avctx); |         avctx->codec->flush(avctx); | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -1671,16 +1700,16 @@ static void video_free_buffers(AVCodecContext *s) | |||||||
|     if (avci->buffer_count) |     if (avci->buffer_count) | ||||||
|         av_log(s, AV_LOG_WARNING, "Found %i unreleased buffers!\n", |         av_log(s, AV_LOG_WARNING, "Found %i unreleased buffers!\n", | ||||||
|                avci->buffer_count); |                avci->buffer_count); | ||||||
|     for(i=0; i<INTERNAL_BUFFER_SIZE; i++){ |     for (i = 0; i < INTERNAL_BUFFER_SIZE; i++) { | ||||||
|         InternalBuffer *buf = &avci->buffer[i]; |         InternalBuffer *buf = &avci->buffer[i]; | ||||||
|         for(j=0; j<4; j++){ |         for (j = 0; j < 4; j++) { | ||||||
|             av_freep(&buf->base[j]); |             av_freep(&buf->base[j]); | ||||||
|             buf->data[j]= NULL; |             buf->data[j] = NULL; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|     av_freep(&avci->buffer); |     av_freep(&avci->buffer); | ||||||
|  |  | ||||||
|     avci->buffer_count=0; |     avci->buffer_count = 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| static void audio_free_buffers(AVCodecContext *avctx) | static void audio_free_buffers(AVCodecContext *avctx) | ||||||
| @@ -1716,7 +1745,7 @@ void avcodec_default_free_buffers(AVCodecContext *avctx) | |||||||
|  |  | ||||||
| int av_get_exact_bits_per_sample(enum AVCodecID codec_id) | int av_get_exact_bits_per_sample(enum AVCodecID codec_id) | ||||||
| { | { | ||||||
|     switch(codec_id){ |     switch (codec_id) { | ||||||
|     case AV_CODEC_ID_ADPCM_CT: |     case AV_CODEC_ID_ADPCM_CT: | ||||||
|     case AV_CODEC_ID_ADPCM_IMA_APC: |     case AV_CODEC_ID_ADPCM_IMA_APC: | ||||||
|     case AV_CODEC_ID_ADPCM_IMA_EA_SEAD: |     case AV_CODEC_ID_ADPCM_IMA_EA_SEAD: | ||||||
| @@ -1923,16 +1952,18 @@ int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes) | |||||||
| } | } | ||||||
|  |  | ||||||
| #if !HAVE_THREADS | #if !HAVE_THREADS | ||||||
| int ff_thread_init(AVCodecContext *s){ | int ff_thread_init(AVCodecContext *s) | ||||||
|  | { | ||||||
|     return -1; |     return -1; | ||||||
| } | } | ||||||
|  |  | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| unsigned int av_xiphlacing(unsigned char *s, unsigned int v) | unsigned int av_xiphlacing(unsigned char *s, unsigned int v) | ||||||
| { | { | ||||||
|     unsigned int n = 0; |     unsigned int n = 0; | ||||||
|  |  | ||||||
|     while(v >= 0xff) { |     while (v >= 0xff) { | ||||||
|         *s++ = 0xff; |         *s++ = 0xff; | ||||||
|         v -= 0xff; |         v -= 0xff; | ||||||
|         n++; |         n++; | ||||||
| @@ -1942,9 +1973,10 @@ unsigned int av_xiphlacing(unsigned char *s, unsigned int v) | |||||||
|     return n; |     return n; | ||||||
| } | } | ||||||
|  |  | ||||||
| int ff_match_2uint16(const uint16_t (*tab)[2], int size, int a, int b){ | int ff_match_2uint16(const uint16_t(*tab)[2], int size, int a, int b) | ||||||
|  | { | ||||||
|     int i; |     int i; | ||||||
|     for(i=0; i<size && !(tab[i][0]==a && tab[i][1]==b); i++); |     for (i = 0; i < size && !(tab[i][0] == a && tab[i][1] == b); i++) ; | ||||||
|     return i; |     return i; | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -1991,13 +2023,12 @@ AVHWAccel *av_hwaccel_next(AVHWAccel *hwaccel) | |||||||
|  |  | ||||||
| AVHWAccel *ff_find_hwaccel(enum AVCodecID codec_id, enum PixelFormat pix_fmt) | AVHWAccel *ff_find_hwaccel(enum AVCodecID codec_id, enum PixelFormat pix_fmt) | ||||||
| { | { | ||||||
|     AVHWAccel *hwaccel=NULL; |     AVHWAccel *hwaccel = NULL; | ||||||
|  |  | ||||||
|     while((hwaccel= av_hwaccel_next(hwaccel))){ |     while ((hwaccel = av_hwaccel_next(hwaccel))) | ||||||
|         if (   hwaccel->id      == codec_id |         if (hwaccel->id == codec_id | ||||||
|             && hwaccel->pix_fmt == pix_fmt) |             && hwaccel->pix_fmt == pix_fmt) | ||||||
|             return hwaccel; |             return hwaccel; | ||||||
|     } |  | ||||||
|     return NULL; |     return NULL; | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -2041,10 +2072,10 @@ int avpriv_unlock_avformat(void) | |||||||
|  |  | ||||||
| unsigned int avpriv_toupper4(unsigned int x) | unsigned int avpriv_toupper4(unsigned int x) | ||||||
| { | { | ||||||
|     return     toupper( x     &0xFF) |     return toupper(x & 0xFF) | ||||||
|             + (toupper((x>>8 )&0xFF)<<8 ) |            + (toupper((x >> 8) & 0xFF) << 8) | ||||||
|             + (toupper((x>>16)&0xFF)<<16) |            + (toupper((x >> 16) & 0xFF) << 16) | ||||||
|             + (toupper((x>>24)&0xFF)<<24); |            + (toupper((x >> 24) & 0xFF) << 24); | ||||||
| } | } | ||||||
|  |  | ||||||
| #if !HAVE_THREADS | #if !HAVE_THREADS | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Luca Barbato
					Luca Barbato