Mercurial > libavcodec.hg
comparison utils.c @ 2806:af3a36e20010 libavcodec
thread mess check for avcodec_open/close()
author | michael |
---|---|
date | Mon, 25 Jul 2005 14:35:01 +0000 |
parents | bf5c4e9dc75a |
children | b128802eb77b |
comparison
equal
deleted
inserted
replaced
2805:55a6659fc2ee | 2806:af3a36e20010 |
---|---|
65 0x03,0x83,0x43,0xC3,0x23,0xA3,0x63,0xE3,0x13,0x93,0x53,0xD3,0x33,0xB3,0x73,0xF3, | 65 0x03,0x83,0x43,0xC3,0x23,0xA3,0x63,0xE3,0x13,0x93,0x53,0xD3,0x33,0xB3,0x73,0xF3, |
66 0x0B,0x8B,0x4B,0xCB,0x2B,0xAB,0x6B,0xEB,0x1B,0x9B,0x5B,0xDB,0x3B,0xBB,0x7B,0xFB, | 66 0x0B,0x8B,0x4B,0xCB,0x2B,0xAB,0x6B,0xEB,0x1B,0x9B,0x5B,0xDB,0x3B,0xBB,0x7B,0xFB, |
67 0x07,0x87,0x47,0xC7,0x27,0xA7,0x67,0xE7,0x17,0x97,0x57,0xD7,0x37,0xB7,0x77,0xF7, | 67 0x07,0x87,0x47,0xC7,0x27,0xA7,0x67,0xE7,0x17,0x97,0x57,0xD7,0x37,0xB7,0x77,0xF7, |
68 0x0F,0x8F,0x4F,0xCF,0x2F,0xAF,0x6F,0xEF,0x1F,0x9F,0x5F,0xDF,0x3F,0xBF,0x7F,0xFF, | 68 0x0F,0x8F,0x4F,0xCF,0x2F,0xAF,0x6F,0xEF,0x1F,0x9F,0x5F,0xDF,0x3F,0xBF,0x7F,0xFF, |
69 }; | 69 }; |
70 | |
71 static int volatile entangled_thread_counter=0; | |
70 | 72 |
71 void avcodec_default_free_buffers(AVCodecContext *s); | 73 void avcodec_default_free_buffers(AVCodecContext *s); |
72 | 74 |
73 void *av_mallocz(unsigned int size) | 75 void *av_mallocz(unsigned int size) |
74 { | 76 { |
520 return pic; | 522 return pic; |
521 } | 523 } |
522 | 524 |
523 int avcodec_open(AVCodecContext *avctx, AVCodec *codec) | 525 int avcodec_open(AVCodecContext *avctx, AVCodec *codec) |
524 { | 526 { |
525 int ret; | 527 int ret= -1; |
528 | |
529 entangled_thread_counter++; | |
530 if(entangled_thread_counter != 1){ | |
531 av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n"); | |
532 goto end; | |
533 } | |
526 | 534 |
527 if(avctx->codec) | 535 if(avctx->codec) |
528 return -1; | 536 goto end; |
529 | 537 |
530 avctx->codec = codec; | 538 avctx->codec = codec; |
531 avctx->codec_id = codec->id; | 539 avctx->codec_id = codec->id; |
532 avctx->frame_number = 0; | 540 avctx->frame_number = 0; |
533 if (codec->priv_data_size > 0) { | 541 if (codec->priv_data_size > 0) { |
534 avctx->priv_data = av_mallocz(codec->priv_data_size); | 542 avctx->priv_data = av_mallocz(codec->priv_data_size); |
535 if (!avctx->priv_data) | 543 if (!avctx->priv_data) |
536 return -ENOMEM; | 544 goto end; |
537 } else { | 545 } else { |
538 avctx->priv_data = NULL; | 546 avctx->priv_data = NULL; |
539 } | 547 } |
540 | 548 |
541 if(avctx->coded_width && avctx->coded_height) | 549 if(avctx->coded_width && avctx->coded_height) |
543 else if(avctx->width && avctx->height) | 551 else if(avctx->width && avctx->height) |
544 avcodec_set_dimensions(avctx, avctx->width, avctx->height); | 552 avcodec_set_dimensions(avctx, avctx->width, avctx->height); |
545 | 553 |
546 if((avctx->coded_width||avctx->coded_height) && avcodec_check_dimensions(avctx,avctx->coded_width,avctx->coded_height)){ | 554 if((avctx->coded_width||avctx->coded_height) && avcodec_check_dimensions(avctx,avctx->coded_width,avctx->coded_height)){ |
547 av_freep(&avctx->priv_data); | 555 av_freep(&avctx->priv_data); |
548 return -1; | 556 goto end; |
549 } | 557 } |
550 | 558 |
551 ret = avctx->codec->init(avctx); | 559 ret = avctx->codec->init(avctx); |
552 if (ret < 0) { | 560 if (ret < 0) { |
553 av_freep(&avctx->priv_data); | 561 av_freep(&avctx->priv_data); |
554 return ret; | 562 goto end; |
555 } | 563 } |
556 return 0; | 564 ret=0; |
565 end: | |
566 entangled_thread_counter--; | |
567 return ret; | |
557 } | 568 } |
558 | 569 |
559 int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size, | 570 int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size, |
560 const short *samples) | 571 const short *samples) |
561 { | 572 { |
668 return ret; | 679 return ret; |
669 } | 680 } |
670 | 681 |
671 int avcodec_close(AVCodecContext *avctx) | 682 int avcodec_close(AVCodecContext *avctx) |
672 { | 683 { |
684 entangled_thread_counter++; | |
685 if(entangled_thread_counter != 1){ | |
686 av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n"); | |
687 entangled_thread_counter--; | |
688 return -1; | |
689 } | |
690 | |
673 if (avctx->codec->close) | 691 if (avctx->codec->close) |
674 avctx->codec->close(avctx); | 692 avctx->codec->close(avctx); |
675 avcodec_default_free_buffers(avctx); | 693 avcodec_default_free_buffers(avctx); |
676 av_freep(&avctx->priv_data); | 694 av_freep(&avctx->priv_data); |
677 avctx->codec = NULL; | 695 avctx->codec = NULL; |
696 entangled_thread_counter--; | |
678 return 0; | 697 return 0; |
679 } | 698 } |
680 | 699 |
681 AVCodec *avcodec_find_encoder(enum CodecID id) | 700 AVCodec *avcodec_find_encoder(enum CodecID id) |
682 { | 701 { |