Skip to content
Snippets Groups Projects
utils.c 48 KiB
Newer Older
  • Learn to ignore specific revisions
  • Fabrice Bellard's avatar
    Fabrice Bellard committed
                snprintf(buf1, sizeof(buf1), "0x%04x", enc->codec_tag);
            }
            codec_name = buf1;
        }
    
        switch(enc->codec_type) {
        case CODEC_TYPE_VIDEO:
            snprintf(buf, buf_size,
                     "Video: %s%s",
    
                     codec_name, enc->mb_decision ? " (hq)" : "");
    
            if (enc->pix_fmt != PIX_FMT_NONE) {
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
                snprintf(buf + strlen(buf), buf_size - strlen(buf),
                         ", %s",
    
                         avcodec_get_pix_fmt_name(enc->pix_fmt));
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
            }
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
            if (enc->width) {
                snprintf(buf + strlen(buf), buf_size - strlen(buf),
                         ", %dx%d, %0.2f fps",
                         enc->width, enc->height, 
    
                         1/av_q2d(enc->time_base));
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
            }
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
            if (encode) {
                snprintf(buf + strlen(buf), buf_size - strlen(buf),
                         ", q=%d-%d", enc->qmin, enc->qmax);
            }
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
            bitrate = enc->bit_rate;
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
            break;
        case CODEC_TYPE_AUDIO:
            snprintf(buf, buf_size,
                     "Audio: %s",
                     codec_name);
    
                    strcpy(channels_str, "mono");
    
                    strcpy(channels_str, "stereo");
    
                    strcpy(channels_str, "5:1");
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
                    snprintf(channels_str, sizeof(channels_str), "%d channels", enc->channels);
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
            if (enc->sample_rate) {
                snprintf(buf + strlen(buf), buf_size - strlen(buf),
                         ", %d Hz, %s",
                         enc->sample_rate,
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
            }
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
            /* for PCM codecs, compute bitrate directly */
            switch(enc->codec_id) {
    
            case CODEC_ID_PCM_S32LE:
            case CODEC_ID_PCM_S32BE:
            case CODEC_ID_PCM_U32LE:
            case CODEC_ID_PCM_U32BE:
                bitrate = enc->sample_rate * enc->channels * 32;
                break;
            case CODEC_ID_PCM_S24LE:
            case CODEC_ID_PCM_S24BE:
            case CODEC_ID_PCM_U24LE:
            case CODEC_ID_PCM_U24BE:
            case CODEC_ID_PCM_S24DAUD:
                bitrate = enc->sample_rate * enc->channels * 24;
                break;
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
            case CODEC_ID_PCM_S16LE:
            case CODEC_ID_PCM_S16BE:
            case CODEC_ID_PCM_U16LE:
            case CODEC_ID_PCM_U16BE:
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
                bitrate = enc->sample_rate * enc->channels * 16;
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
                break;
            case CODEC_ID_PCM_S8:
            case CODEC_ID_PCM_U8:
            case CODEC_ID_PCM_ALAW:
            case CODEC_ID_PCM_MULAW:
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
                bitrate = enc->sample_rate * enc->channels * 8;
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
                break;
            default:
                bitrate = enc->bit_rate;
                break;
            }
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
            break;
    
        case CODEC_TYPE_DATA:
            snprintf(buf, buf_size, "Data: %s", codec_name);
    
            bitrate = enc->bit_rate;
            break;
        case CODEC_TYPE_SUBTITLE:
            snprintf(buf, buf_size, "Subtitle: %s", codec_name);
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
        default:
    
            snprintf(buf, buf_size, "Invalid Codec type %d", enc->codec_type);
            return;
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
        }
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
        if (encode) {
            if (enc->flags & CODEC_FLAG_PASS1)
                snprintf(buf + strlen(buf), buf_size - strlen(buf),
                         ", pass 1");
            if (enc->flags & CODEC_FLAG_PASS2)
                snprintf(buf + strlen(buf), buf_size - strlen(buf),
                         ", pass 2");
        }
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
        if (bitrate != 0) {
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
            snprintf(buf + strlen(buf), buf_size - strlen(buf), 
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
                     ", %d kb/s", bitrate / 1000);
    
    Nick Kurshev's avatar
    Nick Kurshev committed
    unsigned avcodec_version( void )
    {
      return LIBAVCODEC_VERSION_INT;
    }
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
    
    
    Nick Kurshev's avatar
    Nick Kurshev committed
    unsigned avcodec_build( void )
    {
      return LIBAVCODEC_BUILD;
    }
    
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
    /* must be called before any other functions */
    void avcodec_init(void)
    {
    
        static int inited = 0;
    
        if (inited != 0)
    	return;
        inited = 1;
    
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
        dsputil_static_init();
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    /**
     * Flush buffers, should be called when seeking or when swicthing to a different stream.
     */
    
    void avcodec_flush_buffers(AVCodecContext *avctx)
    {
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
        if(avctx->codec->flush)
            avctx->codec->flush(avctx);
    
    void avcodec_default_free_buffers(AVCodecContext *s){
    
        int i, j;
    
        if(s->internal_buffer==NULL) return;
        
        for(i=0; i<INTERNAL_BUFFER_SIZE; i++){
            InternalBuffer *buf= &((InternalBuffer*)s->internal_buffer)[i];
            for(j=0; j<4; j++){
                av_freep(&buf->base[j]);
                buf->data[j]= NULL;
            }
        }
        av_freep(&s->internal_buffer);
        
        s->internal_buffer_count=0;
    }
    
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    char av_get_pict_type_char(int pict_type){
        switch(pict_type){
        case I_TYPE: return 'I'; 
        case P_TYPE: return 'P'; 
        case B_TYPE: return 'B'; 
        case S_TYPE: return 'S'; 
        case SI_TYPE:return 'i'; 
        case SP_TYPE:return 'p'; 
        default:     return '?';
        }
    }
    
    
    static int av_log_level = AV_LOG_INFO;
    
    static void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
    
        static int print_prefix=1;
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
        AVClass* avc= ptr ? *(AVClass**)ptr : NULL;
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
        if(print_prefix && avc) {
    	    fprintf(stderr, "[%s @ %p]", avc->item_name(ptr), avc);
    
    Falk Hüffner's avatar
    Falk Hüffner committed
        print_prefix= strstr(fmt, "\n") != NULL;
    
    static void (*av_log_callback)(void*, int, const char*, va_list) = av_log_default_callback;
    
    void av_log(void* avcl, int level, const char *fmt, ...)
    
    void av_vlog(void* avcl, int level, const char *fmt, va_list vl)
    
        av_log_callback(avcl, level, fmt, vl);
    
    }
    
    int av_log_get_level(void)
    {
        return av_log_level;
    }
    
    void av_log_set_level(int level)
    {
        av_log_level = level;
    }
    
    
    void av_log_set_callback(void (*callback)(void*, int, const char*, va_list))
    
    int avcodec_thread_init(AVCodecContext *s, int thread_count){
        return -1;
    }
    #endif
    
    
    unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
    {
        unsigned int n = 0;
    
        while(v >= 0xff) {
            *s++ = 0xff;
            v -= 0xff;
            n++;
        }
        *s = v;
        n++;
        return n;
    }