OSDN Git Service

Merge commit '38ecc3702dabbea09230f6d6333f59e74f5d1c12'
authorMichael Niedermayer <michaelni@gmx.at>
Mon, 4 Nov 2013 10:14:38 +0000 (11:14 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Mon, 4 Nov 2013 10:14:38 +0000 (11:14 +0100)
* commit '38ecc3702dabbea09230f6d6333f59e74f5d1c12':
  pthread: store thread contexts in AVCodecInternal instead of AVCodecContext

Conflicts:
libavcodec/internal.h
libavcodec/utils.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
libavcodec/avcodec.h
libavcodec/internal.h
libavcodec/options.c
libavcodec/pthread_frame.c
libavcodec/pthread_slice.c
libavcodec/utils.c
libavcodec/version.h

Simple merge
@@@ -95,18 -87,7 +95,20 @@@ typedef struct AVCodecInternal 
  
      FramePool *pool;
  
+     void *thread_ctx;
++
 +    /**
 +     * temporary buffer used for encoders to store their bitstream
 +     */
 +    uint8_t *byte_buffer;
 +    unsigned int byte_buffer_size;
 +
 +    void *frame_thread_encoder;
 +
 +    /**
 +     * Number of audio samples to skip at the start of the next decoded frame
 +     */
 +    int skip_samples;
  } AVCodecInternal;
  
  struct AVCodecDefault {
Simple merge
@@@ -729,19 -680,9 +730,19 @@@ void ff_thread_flush(AVCodecContext *av
      }
  }
  
 -int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
 +int ff_thread_can_start_frame(AVCodecContext *avctx)
 +{
-     PerThreadContext *p = avctx->thread_opaque;
++    PerThreadContext *p = avctx->internal->thread_ctx;
 +    if ((avctx->active_thread_type&FF_THREAD_FRAME) && p->state != STATE_SETTING_UP &&
 +        (avctx->codec->update_thread_context || !THREAD_SAFE_CALLBACKS(avctx))) {
 +        return 0;
 +    }
 +    return 1;
 +}
 +
 +static int thread_get_buffer_internal(AVCodecContext *avctx, ThreadFrame *f, int flags)
  {
-     PerThreadContext *p = avctx->thread_opaque;
+     PerThreadContext *p = avctx->internal->thread_ctx;
      int err;
  
      f->owner = avctx;
@@@ -803,43 -742,9 +804,43 @@@ FF_ENABLE_DEPRECATION_WARNING
      return err;
  }
  
-     PerThreadContext *p = avctx->thread_opaque;
 +enum AVPixelFormat ff_thread_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
 +{
 +    enum AVPixelFormat res;
++    PerThreadContext *p = avctx->internal->thread_ctx;
 +    if (!(avctx->active_thread_type & FF_THREAD_FRAME) || avctx->thread_safe_callbacks ||
 +        avctx->get_format == avcodec_default_get_format)
 +        return avctx->get_format(avctx, fmt);
 +    if (p->state != STATE_SETTING_UP) {
 +        av_log(avctx, AV_LOG_ERROR, "get_format() cannot be called after ff_thread_finish_setup()\n");
 +        return -1;
 +    }
 +    pthread_mutex_lock(&p->progress_mutex);
 +    p->available_formats = fmt;
 +    p->state = STATE_GET_FORMAT;
 +    pthread_cond_broadcast(&p->progress_cond);
 +
 +    while (p->state != STATE_SETTING_UP)
 +        pthread_cond_wait(&p->progress_cond, &p->progress_mutex);
 +
 +    res = p->result_format;
 +
 +    pthread_mutex_unlock(&p->progress_mutex);
 +
 +    return res;
 +}
 +
 +int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
 +{
 +    int ret = thread_get_buffer_internal(avctx, f, flags);
 +    if (ret < 0)
 +        av_log(avctx, AV_LOG_ERROR, "thread_get_buffer() failed\n");
 +    return ret;
 +}
 +
  void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f)
  {
-     PerThreadContext *p = avctx->thread_opaque;
+     PerThreadContext *p = avctx->internal->thread_ctx;
      FrameThreadContext *fctx;
      AVFrame *dst, *tmp;
  FF_DISABLE_DEPRECATION_WARNINGS
@@@ -231,62 -222,3 +231,62 @@@ int ff_slice_thread_init(AVCodecContex
      avctx->execute2 = thread_execute2;
      return 0;
  }
-     SliceThreadContext *p = avctx->thread_opaque;
 +
 +void ff_thread_report_progress2(AVCodecContext *avctx, int field, int thread, int n)
 +{
-     SliceThreadContext *p  = avctx->thread_opaque;
++    SliceThreadContext *p = avctx->internal->thread_ctx;
 +    int *entries = p->entries;
 +
 +    pthread_mutex_lock(&p->progress_mutex[thread]);
 +    entries[field] +=n;
 +    pthread_cond_signal(&p->progress_cond[thread]);
 +    pthread_mutex_unlock(&p->progress_mutex[thread]);
 +}
 +
 +void ff_thread_await_progress2(AVCodecContext *avctx, int field, int thread, int shift)
 +{
-         SliceThreadContext *p = avctx->thread_opaque;
++    SliceThreadContext *p  = avctx->internal->thread_ctx;
 +    int *entries      = p->entries;
 +
 +    if (!entries || !field) return;
 +
 +    thread = thread ? thread - 1 : p->thread_count - 1;
 +
 +    pthread_mutex_lock(&p->progress_mutex[thread]);
 +    while ((entries[field - 1] - entries[field]) < shift){
 +        pthread_cond_wait(&p->progress_cond[thread], &p->progress_mutex[thread]);
 +    }
 +    pthread_mutex_unlock(&p->progress_mutex[thread]);
 +}
 +
 +int ff_alloc_entries(AVCodecContext *avctx, int count)
 +{
 +    int i;
 +
 +    if (avctx->active_thread_type & FF_THREAD_SLICE)  {
-     SliceThreadContext *p = avctx->thread_opaque;
++        SliceThreadContext *p = avctx->internal->thread_ctx;
 +        p->thread_count  = avctx->thread_count;
 +        p->entries       = av_mallocz(count * sizeof(int));
 +
 +        if (!p->entries) {
 +            return AVERROR(ENOMEM);
 +        }
 +
 +        p->entries_count  = count;
 +        p->progress_mutex = av_malloc(p->thread_count * sizeof(pthread_mutex_t));
 +        p->progress_cond  = av_malloc(p->thread_count * sizeof(pthread_cond_t));
 +
 +        for (i = 0; i < p->thread_count; i++) {
 +            pthread_mutex_init(&p->progress_mutex[i], NULL);
 +            pthread_cond_init(&p->progress_cond[i], NULL);
 +        }
 +    }
 +
 +    return 0;
 +}
 +
 +void ff_reset_entries(AVCodecContext *avctx)
 +{
++    SliceThreadContext *p = avctx->internal->thread_ctx;
 +    memset(p->entries, 0, p->entries_count * sizeof(int));
 +}
@@@ -2552,13 -1567,7 +2552,13 @@@ av_cold int avcodec_close(AVCodecContex
      if (avcodec_is_open(avctx)) {
          FramePool *pool = avctx->internal->pool;
          int i;
-         if (HAVE_THREADS && avctx->thread_opaque)
 +        if (CONFIG_FRAME_THREAD_ENCODER &&
 +            avctx->internal->frame_thread_encoder && avctx->thread_count > 1) {
 +            ff_unlock_avcodec();
 +            ff_frame_thread_encoder_free(avctx);
 +            ff_lock_avcodec(avctx);
 +        }
+         if (HAVE_THREADS && avctx->internal->thread_ctx)
              ff_thread_free(avctx);
          if (avctx->codec && avctx->codec->close)
              avctx->codec->close(avctx);
Simple merge