Ejemplo n.º 1
0
/* constructor */
static tsk_object_t* tdav_codec_mp4ves_ctor(tsk_object_t * _self, va_list * app)
{
	tdav_codec_mp4ves_t *self = _self;
	if(self){
		/* init base: called by tmedia_codec_create() */
		/* init self */
		self->profile = DEFAULT_PROFILE_LEVEL_ID;
		self->encoder.quality = 1;
		self->encoder.max_bw_kpbs = tmedia_defaults_get_bandwidth_video_upload_max();
	}
	return self;
}
Ejemplo n.º 2
0
int tdav_codec_h264_init(tdav_codec_h264_t* self, profile_idc_t profile)
{
	int ret = 0;
	level_idc_t level;

	if(!self){
		TSK_DEBUG_ERROR("Invalid parameter");
		return -1;
	}

	if((ret = tdav_codec_h264_common_init(TDAV_CODEC_H264_COMMON(self)))){
		TSK_DEBUG_ERROR("tdav_codec_h264_common_init() faile with error code=%d", ret);
		return ret;
	}

	if((ret = tdav_codec_h264_common_level_from_size(TMEDIA_CODEC_VIDEO(self)->out.width, TMEDIA_CODEC_VIDEO(self)->out.height, &level))){
		TSK_DEBUG_ERROR("Failed to find level for size=[%u, %u]", TMEDIA_CODEC_VIDEO(self)->out.width, TMEDIA_CODEC_VIDEO(self)->out.height);
		return ret;
	}

	(self)->encoder.max_bw_kpbs = tmedia_defaults_get_bandwidth_video_upload_max();
	TDAV_CODEC_H264_COMMON(self)->pack_mode = H264_PACKETIZATION_MODE;
	TDAV_CODEC_H264_COMMON(self)->profile = profile;
	TDAV_CODEC_H264_COMMON(self)->level = level;
	TMEDIA_CODEC_VIDEO(self)->in.max_mbps = TMEDIA_CODEC_VIDEO(self)->out.max_mbps = H264_MAX_MBPS*1000;
	TMEDIA_CODEC_VIDEO(self)->in.max_br = TMEDIA_CODEC_VIDEO(self)->out.max_br = H264_MAX_BR*1000;

#if HAVE_FFMPEG
	if(!(self->encoder.codec = avcodec_find_encoder(CODEC_ID_H264))){
		TSK_DEBUG_ERROR("Failed to find H.264 encoder");
		ret = -2;
	}

	if(!(self->decoder.codec = avcodec_find_decoder(CODEC_ID_H264))){
		TSK_DEBUG_ERROR("Failed to find H.264 decoder");
		ret = -3;
	}
#endif
#if HAVE_H264_PASSTHROUGH
	TMEDIA_CODEC(self)->passthrough = tsk_true;
	self->decoder.passthrough = tsk_true;
	self->encoder.passthrough = tsk_true;
#endif

	self->encoder.quality = 1;

	/* allocations MUST be done by open() */
	return ret;
}
Ejemplo n.º 3
0
/**@ingroup tmedia_codec_group
* Initialize a Codec
* @param self The codec to initialize. Could be any type of codec (e.g. @ref tmedia_codec_audio_t or @ref tmedia_codec_video_t).
* @param type
* @param name the name of the codec. e.g. "G.711u" or "G.711a" etc used in the sdp.
* @param desc full description.
* @param format the format. e.g. "0" for G.711.u or "8" for G.711a or "*" for MSRP.
* @retval Zero if succeed and non-zero error code otherwise.
*/
int tmedia_codec_init(tmedia_codec_t* self, tmedia_type_t type, const char* name, const char* desc, const char* format)
{
    if(!self || tsk_strnullORempty(name)) {
        TSK_DEBUG_ERROR("Invalid parameter");
        return -1;
    }
    self->type = type;
    tsk_strupdate(&self->name, name);
    tsk_strupdate(&self->desc,desc);
    tsk_strupdate(&self->format, format);
    if(!self->bandwidth_max_upload) {
        self->bandwidth_max_upload = (type == tmedia_video ? tmedia_defaults_get_bandwidth_video_upload_max() : INT_MAX);    // INT_MAX or <=0 means undefined
    }
    if(!self->bandwidth_max_download) {
        self->bandwidth_max_download = (type == tmedia_video ? tmedia_defaults_get_bandwidth_video_download_max() : INT_MAX);    // INT_MAX or <=0 means undefined
    }
    if(!self->in.rate) {
        self->in.rate = self->plugin->rate;
    }
    if(!self->out.rate) {
        self->out.rate = self->plugin->rate;
    }

    if(type & tmedia_audio) {
        tmedia_codec_audio_t* audio = TMEDIA_CODEC_AUDIO(self);
        if(!audio->in.ptime) {
            audio->in.ptime = (self->plugin->audio.ptime ? self->plugin->audio.ptime : tmedia_defaults_get_audio_ptime());
        }
        if(!audio->out.ptime) {
            audio->out.ptime = (self->plugin->audio.ptime ? self->plugin->audio.ptime : tmedia_defaults_get_audio_ptime());
        }
        if(!audio->in.channels) {
            audio->in.channels = self->plugin->audio.channels;
        }
        if(!audio->out.channels) {
            audio->out.channels = self->plugin->audio.channels;
        }
        if(!audio->in.timestamp_multiplier) {
            audio->in.timestamp_multiplier = tmedia_codec_audio_get_timestamp_multiplier(self->id, self->in.rate);
        }
        if(!audio->out.timestamp_multiplier) {
            audio->out.timestamp_multiplier = tmedia_codec_audio_get_timestamp_multiplier(self->id, self->out.rate);
        }
    }
    // Video flipping: For backward compatibility we have to initialize the default values
    // according to the CFLAGS: 'FLIP_ENCODED_PICT' and 'FLIP_DECODED_PICT'. At any time you
    // can update thse values (e.g. when the device switch from landscape to portrait) using video_session->set();
    else if(type & tmedia_video) {
        tmedia_codec_video_t* video = TMEDIA_CODEC_VIDEO(self);
#if FLIP_ENCODED_PICT
        video->out.flip = tsk_true;
#endif
#if FLIP_DECODED_PICT
        video->in.flip = tsk_true;
#endif
        if(!video->in.fps) {
            video->in.fps = self->plugin->video.fps ? self->plugin->video.fps : tmedia_defaults_get_video_fps();
        }
        if(!video->out.fps) {
            video->out.fps = self->plugin->video.fps ? self->plugin->video.fps : tmedia_defaults_get_video_fps();
        }
        if(video->in.chroma == tmedia_chroma_none) {
            video->in.chroma = tmedia_chroma_yuv420p;
        }
        if(video->out.chroma == tmedia_chroma_none) {
            video->out.chroma = tmedia_chroma_yuv420p;
        }

        if(0) { // @deprecated
            if(!video->in.width) {
                video->in.width = video->out.width = self->plugin->video.width;
            }
            if(!video->in.height) {
                video->in.height = video->out.height = self->plugin->video.height;
            }
        }
        else {
            int ret;
            unsigned width, height;
            video->pref_size = tmedia_defaults_get_pref_video_size();
            if((ret = tmedia_video_get_size(video->pref_size, &width, &height)) != 0) {
                width = self->plugin->video.width;
                height = self->plugin->video.height;
            }
            if(!video->in.width) {
                video->in.width = video->out.width = width;
            }
            if(!video->in.height) {
                video->in.height = video->out.height = height;
            }
        }

    }

    return 0;
}