~ubuntu-branches/ubuntu/saucy/gst-libav1.0/saucy-proposed

« back to all changes in this revision

Viewing changes to gst-libs/ext/libav/libavcodec/pthread.c

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2013-07-30 09:00:15 UTC
  • mfrom: (1.1.16) (7.1.7 experimental)
  • Revision ID: package-import@ubuntu.com-20130730090015-sc1ou2yssu7q5w4e
Tags: 1.1.3-1
* New upstream development snapshot:
  + debian/control:
    - Build depend on GStreamer and gst-plugins-base >= 1.1.3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
#include "avcodec.h"
53
53
#include "internal.h"
54
54
#include "thread.h"
 
55
#include "libavutil/common.h"
55
56
 
56
57
#if HAVE_PTHREADS
57
58
#include <pthread.h>
356
357
    PerThreadContext *p = arg;
357
358
    FrameThreadContext *fctx = p->parent;
358
359
    AVCodecContext *avctx = p->avctx;
359
 
    AVCodec *codec = avctx->codec;
 
360
    const AVCodec *codec = avctx->codec;
360
361
 
361
362
    while (1) {
362
363
        if (p->state == STATE_INPUT_READY && !fctx->die) {
376
377
        p->got_frame = 0;
377
378
        p->result = codec->decode(avctx, &p->frame, &p->got_frame, &p->avpkt);
378
379
 
 
380
        /* many decoders assign whole AVFrames, thus overwriting extended_data;
 
381
         * make sure it's set correctly */
 
382
        p->frame.extended_data = p->frame.data;
 
383
 
379
384
        if (p->state == STATE_SETTING_UP) ff_thread_finish_setup(avctx);
380
385
 
381
386
        p->state = STATE_INPUT_READY;
402
407
    int err = 0;
403
408
 
404
409
    if (dst != src) {
405
 
        dst->sub_id    = src->sub_id;
406
410
        dst->time_base = src->time_base;
407
411
        dst->width     = src->width;
408
412
        dst->height    = src->height;
458
462
    dst->release_buffer = src->release_buffer;
459
463
 
460
464
    dst->opaque   = src->opaque;
461
 
    dst->dsp_mask = src->dsp_mask;
462
465
    dst->debug    = src->debug;
463
466
    dst->debug_mv = src->debug_mv;
464
467
 
465
468
    dst->slice_flags = src->slice_flags;
466
469
    dst->flags2      = src->flags2;
467
470
 
468
 
    copy_fields(skip_loop_filter, bidir_refine);
 
471
    copy_fields(skip_loop_filter, subtitle_header);
469
472
 
470
473
    dst->frame_number     = src->frame_number;
471
474
    dst->reordered_opaque = src->reordered_opaque;
518
521
{
519
522
    FrameThreadContext *fctx = p->parent;
520
523
    PerThreadContext *prev_thread = fctx->prev_thread;
521
 
    AVCodec *codec = p->avctx->codec;
 
524
    const AVCodec *codec = p->avctx->codec;
522
525
    uint8_t *buf = p->avpkt.data;
523
526
 
524
527
    if (!avpkt->size && !(codec->capabilities & CODEC_CAP_DELAY)) return 0;
567
570
                pthread_cond_wait(&p->progress_cond, &p->progress_mutex);
568
571
 
569
572
            if (p->state == STATE_GET_BUFFER) {
570
 
                p->result = p->avctx->get_buffer(p->avctx, p->requested_frame);
 
573
                p->result = ff_get_buffer(p->avctx, p->requested_frame);
571
574
                p->state  = STATE_SETTING_UP;
572
575
                pthread_cond_signal(&p->progress_cond);
573
576
            }
604
607
     * If we're still receiving the initial packets, don't return a frame.
605
608
     */
606
609
 
607
 
    if (fctx->delaying && avpkt->size) {
 
610
    if (fctx->delaying) {
608
611
        if (fctx->next_decoding >= (avctx->thread_count-1)) fctx->delaying = 0;
609
612
 
610
613
        *got_picture_ptr=0;
611
 
        return avpkt->size;
 
614
        if (avpkt->size)
 
615
            return avpkt->size;
612
616
    }
613
617
 
614
618
    /*
631
635
        *picture = p->frame;
632
636
        *got_picture_ptr = p->got_frame;
633
637
        picture->pkt_dts = p->avpkt.dts;
634
 
        picture->sample_aspect_ratio = p->avctx->sample_aspect_ratio;
635
 
        picture->width  = p->avctx->width;
636
 
        picture->height = p->avctx->height;
637
 
        picture->format = p->avctx->pix_fmt;
638
638
 
639
639
        /*
640
640
         * A later call with avkpt->size == 0 may loop over all threads,
724
724
static void frame_thread_free(AVCodecContext *avctx, int thread_count)
725
725
{
726
726
    FrameThreadContext *fctx = avctx->thread_opaque;
727
 
    AVCodec *codec = avctx->codec;
 
727
    const AVCodec *codec = avctx->codec;
728
728
    int i;
729
729
 
730
730
    park_frame_worker_threads(fctx, thread_count);
781
781
static int frame_thread_init(AVCodecContext *avctx)
782
782
{
783
783
    int thread_count = avctx->thread_count;
784
 
    AVCodec *codec = avctx->codec;
 
784
    const AVCodec *codec = avctx->codec;
785
785
    AVCodecContext *src = avctx;
786
786
    FrameThreadContext *fctx;
787
787
    int i, err = 0;
870
870
 
871
871
void ff_thread_flush(AVCodecContext *avctx)
872
872
{
 
873
    int i;
873
874
    FrameThreadContext *fctx = avctx->thread_opaque;
874
875
 
875
876
    if (!avctx->thread_opaque) return;
885
886
    fctx->next_decoding = fctx->next_finished = 0;
886
887
    fctx->delaying = 1;
887
888
    fctx->prev_thread = NULL;
 
889
    for (i = 0; i < avctx->thread_count; i++) {
 
890
        PerThreadContext *p = &fctx->threads[i];
 
891
        // Make sure decode flush calls with size=0 won't return old frames
 
892
        p->got_frame = 0;
 
893
 
 
894
        release_delayed_buffers(p);
 
895
    }
888
896
}
889
897
 
890
898
static int *allocate_progress(PerThreadContext *p)
913
921
 
914
922
    if (!(avctx->active_thread_type&FF_THREAD_FRAME)) {
915
923
        f->thread_opaque = NULL;
916
 
        return avctx->get_buffer(avctx, f);
 
924
        return ff_get_buffer(avctx, f);
917
925
    }
918
926
 
919
927
    if (p->state != STATE_SETTING_UP &&
935
943
 
936
944
    if (avctx->thread_safe_callbacks ||
937
945
        avctx->get_buffer == avcodec_default_get_buffer) {
938
 
        err = avctx->get_buffer(avctx, f);
 
946
        err = ff_get_buffer(avctx, f);
939
947
    } else {
940
948
        p->requested_frame = f;
941
949
        p->state = STATE_GET_BUFFER;
953
961
            ff_thread_finish_setup(avctx);
954
962
    }
955
963
 
 
964
    if (err) {
 
965
        free_progress(f);
 
966
        f->thread_opaque = NULL;
 
967
    }
956
968
    pthread_mutex_unlock(&p->parent->buffer_mutex);
957
969
 
958
970
    return err;
1009
1021
        avctx->thread_count       = 1;
1010
1022
        avctx->active_thread_type = 0;
1011
1023
    }
 
1024
 
 
1025
    if (avctx->thread_count > MAX_AUTO_THREADS)
 
1026
        av_log(avctx, AV_LOG_WARNING,
 
1027
               "Application has requested %d threads. Using a thread count greater than %d is not recommended.\n",
 
1028
               avctx->thread_count, MAX_AUTO_THREADS);
1012
1029
}
1013
1030
 
1014
1031
int ff_thread_init(AVCodecContext *avctx)