~ubuntu-branches/ubuntu/quantal/linphone/quantal

« back to all changes in this revision

Viewing changes to mediastreamer2/src/videoenc.c

  • Committer: Bazaar Package Importer
  • Author(s): Lionel Elie Mamane, Kilian Krause, Lionel Elie Mamane
  • Date: 2009-05-27 11:39:51 UTC
  • mfrom: (5.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090527113951-jd525e5rlwluh617
[ Kilian Krause ]
* Remove -N from wget args in get-orig-source target as -O is already
  used.

[ Lionel Elie Mamane ]
* linphone: Fix file conflict with linphone-common (<= 3.1.2-1)
  (Closes: #528076)

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#else
27
27
#include <ffmpeg/avcodec.h>
28
28
#endif
 
29
 
29
30
#include "mediastreamer2/msfilter.h"
30
31
#include "mediastreamer2/msvideo.h"
31
32
#include "mediastreamer2/msticker.h"
40
41
 
41
42
static bool_t avcodec_initialized=FALSE;
42
43
 
 
44
#ifdef ENABLE_LOG_FFMPEG
 
45
 
 
46
void ms_ffmpeg_log_callback(void* ptr, int level, const char* fmt, va_list vl)
 
47
{
 
48
        static char message[8192];
 
49
 
 
50
    vsnprintf(message, sizeof message, fmt, vl);
 
51
        ms_message(message);
 
52
}
 
53
 
 
54
#endif
 
55
 
43
56
void ms_ffmpeg_check_init(){
44
57
        if(!avcodec_initialized){
45
58
                avcodec_init();
46
59
                avcodec_register_all();
47
60
                avcodec_initialized=TRUE;
 
61
#ifdef ENABLE_LOG_FFMPEG
 
62
                av_log_set_level(AV_LOG_WARNING);
 
63
                av_log_set_callback(&ms_ffmpeg_log_callback);
 
64
#endif
48
65
        }
49
66
}
50
67
 
59
76
        float fps;
60
77
        int maxbr;
61
78
        int qmin;
 
79
        uint32_t framenum;
62
80
        bool_t req_vfu;
63
81
}EncState;
64
82
 
153
171
        f->data=s;
154
172
        ms_ffmpeg_check_init();
155
173
        s->profile=0;/*always default to profile 0*/
156
 
        s->comp_buf=allocb(32000,0);
 
174
        s->comp_buf=NULL;
157
175
        s->fps=15;
158
176
        s->mtu=ms_get_payload_max_size()-2;/*-2 for the H263 payload header*/
159
177
        s->maxbr=500000;
162
180
        s->vsize.height=MS_VIDEO_SIZE_CIF_H;
163
181
        s->qmin=2;
164
182
        s->req_vfu=FALSE;
 
183
        s->framenum=0;
165
184
        s->av_context.codec=NULL;
166
185
}
167
186
 
188
207
                /*snow does not like 1st pass rate control*/
189
208
                /*and rate control eats too much cpu with CIF high fps pictures*/
190
209
                c->rc_max_rate=(float)s->maxbr*0.8;
191
 
                c->rc_min_rate=c->bit_rate;
 
210
                c->rc_min_rate=0;
192
211
                c->rc_buffer_size=c->rc_max_rate;
193
212
        }else{
194
213
                /*use qmin instead*/
202
221
        c->time_base.den = (int)s->fps;
203
222
        c->gop_size=(int)s->fps*5; /*emit I frame every 5 seconds*/
204
223
        c->pix_fmt=PIX_FMT_YUV420P;
205
 
        
 
224
        s->comp_buf=allocb(c->bit_rate*2,0);
206
225
        if (s->codec==CODEC_ID_SNOW){
207
226
                c->strict_std_compliance=-2;
208
227
        }
245
264
 
246
265
static void enc_uninit(MSFilter  *f){
247
266
        EncState *s=(EncState*)f->data;
248
 
        if (s->comp_buf!=NULL)  freemsg(s->comp_buf);
249
267
        ms_free(s);
250
268
}
251
269
#if 0
292
310
                avcodec_close(&s->av_context);
293
311
                s->av_context.codec=NULL;
294
312
        }
 
313
        if (s->comp_buf!=NULL)  {
 
314
                freemsg(s->comp_buf);
 
315
                s->comp_buf=NULL;
 
316
        }
295
317
}
296
318
 
297
319
static void add_rfc2190_header(mblk_t **packet, AVCodecContext *context){
455
477
        int error;
456
478
        mblk_t *comp_buf=s->comp_buf;
457
479
        int comp_buf_sz=comp_buf->b_datap->db_lim-comp_buf->b_datap->db_base;
458
 
        
 
480
 
459
481
        /* convert image if necessary */
460
482
        avcodec_get_frame_defaults(&pict);
461
483
        avpicture_fill((AVPicture*)&pict,(uint8_t*)inm->b_rptr,c->pix_fmt,c->width,c->height);
462
484
        
463
485
        /* timestamp used by ffmpeg, unset here */
464
486
        pict.pts=AV_NOPTS_VALUE;
 
487
                
 
488
        if (s->framenum==(int)(s->fps*2.0) || s->framenum==(int)(s->fps*4.0)){
 
489
                /*sends an I frame at 2 seconds and 4 seconds after the beginning of the call*/
 
490
                s->req_vfu=TRUE;
 
491
        }
465
492
        if (s->req_vfu){
466
493
                pict.pict_type=FF_I_TYPE;
467
494
                s->req_vfu=FALSE;
477
504
        error=avcodec_encode_video(c, (uint8_t*)comp_buf->b_wptr,comp_buf_sz, &pict);
478
505
        if (error<=0) ms_warning("ms_AVencoder_process: error %i.",error);
479
506
        else{
 
507
                s->framenum++;
480
508
                if (c->coded_frame->pict_type==FF_I_TYPE){
481
509
                        ms_message("Emitting I-frame");
482
510
                }
512
540
        bool_t snow=s->codec==CODEC_ID_SNOW;
513
541
        s->maxbr=*(int*)arg;
514
542
        if (s->maxbr>=1024000 && s->codec!=CODEC_ID_H263P){
515
 
                s->vsize.width = MS_VIDEO_SIZE_4CIF_W;
516
 
                s->vsize.height = MS_VIDEO_SIZE_4CIF_H;
 
543
                s->vsize.width = MS_VIDEO_SIZE_SVGA_W;
 
544
                s->vsize.height = MS_VIDEO_SIZE_SVGA_H;
 
545
                s->fps=17;
 
546
        }else if (s->maxbr>=800000 && s->codec!=CODEC_ID_H263P){
 
547
                s->vsize.width = MS_VIDEO_SIZE_VGA_W;
 
548
                s->vsize.height = MS_VIDEO_SIZE_VGA_H;
517
549
                s->fps=17;
518
550
        }else if (s->maxbr>=512000){
519
551
                s->vsize.width=MS_VIDEO_SIZE_CIF_W;
569
601
MSFilterDesc ms_h263_enc_desc={
570
602
        MS_H263_ENC_ID,
571
603
        "MSH263Enc",
572
 
        "A video H.263 encoder using ffmpeg library.",
 
604
        N_("A video H.263 encoder using ffmpeg library."),
573
605
        MS_FILTER_ENCODER,
574
606
        "H263-1998",
575
607
        1, /*MS_YUV420P is assumed on this input */
585
617
MSFilterDesc ms_h263_old_enc_desc={
586
618
        MS_H263_OLD_ENC_ID,
587
619
        "MSH263OldEnc",
588
 
        "A video H.263 encoder using ffmpeg library. It is compliant with old RFC2190 spec.",
 
620
        N_("A video H.263 encoder using ffmpeg library. It is compliant with old RFC2190 spec."),
589
621
        MS_FILTER_ENCODER,
590
622
        "H263",
591
623
        1, /*MS_YUV420P is assumed on this input */
601
633
MSFilterDesc ms_mpeg4_enc_desc={
602
634
        MS_MPEG4_ENC_ID,
603
635
        "MSMpeg4Enc",
604
 
        "A video MPEG4 encoder using ffmpeg library.",
 
636
        N_("A video MPEG4 encoder using ffmpeg library."),
605
637
        MS_FILTER_ENCODER,
606
638
        "MP4V-ES",
607
639
        1, /*MS_YUV420P is assumed on this input */
617
649
MSFilterDesc ms_snow_enc_desc={
618
650
        MS_SNOW_ENC_ID,
619
651
        "MSSnowEnc",
620
 
        "A video snow encoder using ffmpeg library.",
 
652
        N_("A video snow encoder using ffmpeg library."),
621
653
        MS_FILTER_ENCODER,
622
654
        "x-snow",
623
655
        1, /*MS_YUV420P is assumed on this input */
635
667
MSFilterDesc ms_h263_enc_desc={
636
668
        .id=MS_H263_ENC_ID,
637
669
        .name="MSH263Enc",
638
 
        .text="A video H.263 encoder using ffmpeg library.",
 
670
        .text=N_("A video H.263 encoder using ffmpeg library."),
639
671
        .category=MS_FILTER_ENCODER,
640
672
        .enc_fmt="H263-1998",
641
673
        .ninputs=1, /*MS_YUV420P is assumed on this input */
651
683
MSFilterDesc ms_h263_old_enc_desc={
652
684
        .id=MS_H263_OLD_ENC_ID,
653
685
        .name="MSH263Enc",
654
 
        .text="A video H.263 encoder using ffmpeg library, compliant with old RFC2190 spec.",
 
686
        .text=N_("A video H.263 encoder using ffmpeg library, compliant with old RFC2190 spec."),
655
687
        .category=MS_FILTER_ENCODER,
656
688
        .enc_fmt="H263",
657
689
        .ninputs=1, /*MS_YUV420P is assumed on this input */
667
699
MSFilterDesc ms_mpeg4_enc_desc={
668
700
        .id=MS_MPEG4_ENC_ID,
669
701
        .name="MSMpeg4Enc",
670
 
        .text="A video MPEG4 encoder using ffmpeg library.",
 
702
        .text=N_("A video MPEG4 encoder using ffmpeg library."),
671
703
        .category=MS_FILTER_ENCODER,
672
704
        .enc_fmt="MP4V-ES",
673
705
        .ninputs=1, /*MS_YUV420P is assumed on this input */
683
715
MSFilterDesc ms_snow_enc_desc={
684
716
        .id=MS_SNOW_ENC_ID,
685
717
        .name="MSSnowEnc",
686
 
        .text="The snow codec is royalty-free and is open-source. \n"
687
 
                "It uses innovative techniques that makes it one of the best video "
 
718
        .text=N_("The snow codec is royalty-free and is open-source. \n"
 
719
                "It uses innovative techniques that makes it one of most promising video "
688
720
                "codec. It is implemented within the ffmpeg project.\n"
689
 
                "However it is under development and compatibility with other versions "
690
 
                "cannot be guaranteed.",
 
721
                "However it is under development, quite unstable and compatibility with other versions "
 
722
                "cannot be guaranteed."),
691
723
        .category=MS_FILTER_ENCODER,
692
724
        .enc_fmt="x-snow",
693
725
        .ninputs=1, /*MS_YUV420P is assumed on this input */
702
734
 
703
735
#endif
704
736
 
 
737
void __register_ffmpeg_encoders_if_possible(void){
 
738
        ms_ffmpeg_check_init();
 
739
        if (avcodec_find_encoder(CODEC_ID_MPEG4))
 
740
                ms_filter_register(&ms_mpeg4_enc_desc);
 
741
        if (avcodec_find_encoder(CODEC_ID_H263)){
 
742
                ms_filter_register(&ms_h263_enc_desc);
 
743
                ms_filter_register(&ms_h263_old_enc_desc);
 
744
        }
 
745
        if (avcodec_find_encoder(CODEC_ID_SNOW))
 
746
                ms_filter_register(&ms_snow_enc_desc);
 
747
}
 
748
 
 
749
/*
705
750
MS_FILTER_DESC_EXPORT(ms_mpeg4_enc_desc)
706
751
MS_FILTER_DESC_EXPORT(ms_h263_enc_desc)
707
752
MS_FILTER_DESC_EXPORT(ms_h263_old_enc_desc)
708
753
MS_FILTER_DESC_EXPORT(ms_snow_enc_desc)
709
 
 
 
754
*/