Пример #1
0
VideoScaledDataNode * dc_video_scaler_node_create(int width, int height, int crop_x, int crop_y, int pix_fmt)
{
	VideoScaledDataNode *video_scaled_data_node = gf_malloc(sizeof(VideoDataNode));
	if (video_scaled_data_node) {
		video_scaled_data_node->v_frame = FF_ALLOC_FRAME();
		if (crop_x || crop_y) {
			video_scaled_data_node->cropped_frame = FF_ALLOC_FRAME();
		} else {
			video_scaled_data_node->cropped_frame = NULL;
		}
	}
	if (!video_scaled_data_node || !video_scaled_data_node->v_frame || ((crop_x || crop_y) && !video_scaled_data_node->cropped_frame)) {
		GF_LOG(GF_LOG_ERROR, GF_LOG_DASH, ("Cannot allocate VideoNode!\n"));
		av_frame_free(&video_scaled_data_node->v_frame);
		av_frame_free(&video_scaled_data_node->cropped_frame);
		gf_free(video_scaled_data_node);
		return NULL;
	}

	/* Determine required buffer size and allocate buffer */
	avpicture_alloc((AVPicture*)video_scaled_data_node->v_frame, pix_fmt, width, height);
	if (video_scaled_data_node->cropped_frame) {
		avpicture_alloc((AVPicture*)video_scaled_data_node->cropped_frame, pix_fmt, width-crop_x, height-crop_y);
	}

	return video_scaled_data_node;
}
Пример #2
0
int dc_audio_input_data_init(AudioInputData *audio_input_data, int channels, int samplerate, int num_consumers, int mode)
{
    int i;

    dc_producer_init(&audio_input_data->producer, AUDIO_CB_SIZE, "audio decoder");
    dc_circular_buffer_create(&audio_input_data->circular_buf, AUDIO_CB_SIZE, mode, num_consumers);

    for (i = 0; i < AUDIO_CB_SIZE; i++) {
        AudioDataNode *audio_data_node = (AudioDataNode*)gf_malloc(sizeof(AudioDataNode));
        audio_input_data->circular_buf.list[i].data = (void *) audio_data_node;

        audio_data_node->abuf_size = MAX_AUDIO_PACKET_SIZE;
        audio_data_node->abuf = (uint8_t*)gf_malloc(audio_data_node->abuf_size * sizeof(uint8_t));
    }

    audio_input_data->aframe = FF_ALLOC_FRAME();
    if (audio_input_data->aframe == NULL) {
        GF_LOG(GF_LOG_ERROR, GF_LOG_DASH, ("Cannot initialize AudioInputData"));
        return -1;
    }

    audio_input_data->channels = channels;
    audio_input_data->samplerate = samplerate;

    return 0;
}
Пример #3
0
int dc_video_input_data_init(VideoInputData *video_input_data, /*int width, int height, int pix_fmt*/ int num_consumers, int mode, int max_source, int video_cb_size)
{
	int i;

	dc_producer_init(&video_input_data->producer, video_cb_size, "video decoder");

	//video_input_data->width = width;
	//video_input_data->height = height;
	//video_input_data->pix_fmt = pix_fmt;

	video_input_data->vprop = (VideoInputProp*)gf_malloc(max_source * sizeof(VideoInputProp));

	dc_circular_buffer_create(&video_input_data->circular_buf, video_cb_size, mode, num_consumers);

	for (i=0; i<video_cb_size; i++) {
		VideoDataNode *video_data_node;
		GF_SAFEALLOC(video_data_node, VideoDataNode);
		video_input_data->circular_buf.list[i].data = (void *) video_data_node;
		video_data_node->vframe = FF_ALLOC_FRAME();
	}

	return 0;
}
Пример #4
0
int dc_audio_encoder_open(AudioOutputFile *audio_output_file, AudioDataConf *audio_data_conf)
{
	AVDictionary *opts = NULL;

	audio_output_file->fifo = av_fifo_alloc(2 * MAX_AUDIO_PACKET_SIZE);
	audio_output_file->aframe = FF_ALLOC_FRAME();
	audio_output_file->adata_buf = (uint8_t*) av_malloc(2 * MAX_AUDIO_PACKET_SIZE);
#ifndef GPAC_USE_LIBAV
	audio_output_file->aframe->channels = -1;
#endif
#ifndef LIBAV_FRAME_OLD
	audio_output_file->aframe->channel_layout = 0;
	audio_output_file->aframe->sample_rate = -1;
#endif
	audio_output_file->aframe->format = -1;
	audio_output_file->codec = avcodec_find_encoder_by_name(audio_data_conf->codec);
	if (audio_output_file->codec == NULL) {
		GF_LOG(GF_LOG_ERROR, GF_LOG_DASH, ("Output audio codec not found\n"));
		return -1;
	}

	audio_output_file->codec_ctx = avcodec_alloc_context3(audio_output_file->codec);
	audio_output_file->codec_ctx->codec_id = audio_output_file->codec->id;
	audio_output_file->codec_ctx->codec_type = AVMEDIA_TYPE_AUDIO;
	audio_output_file->codec_ctx->bit_rate = audio_data_conf->bitrate;
	audio_output_file->codec_ctx->sample_rate = DC_AUDIO_SAMPLE_RATE /*audio_data_conf->samplerate*/;

	{
		AVRational time_base;
		time_base.num = 1;
		time_base.den = audio_output_file->codec_ctx->sample_rate;
		audio_output_file->codec_ctx->time_base = time_base;
	}
	audio_output_file->codec_ctx->channels = audio_data_conf->channels;
	audio_output_file->codec_ctx->channel_layout = AV_CH_LAYOUT_STEREO; /*FIXME: depends on channels -> http://ffmpeg.org/doxygen/trunk/channel__layout_8c_source.html#l00074*/
	audio_output_file->codec_ctx->sample_fmt = audio_output_file->codec->sample_fmts[0];
#ifdef DC_AUDIO_RESAMPLER
	audio_output_file->aresampler = NULL;
#endif
	if (audio_data_conf->custom) {
		build_dict(audio_output_file->codec_ctx->priv_data, audio_data_conf->custom);
	}
	audio_output_file->astream_idx = 0;

	/* open the audio codec */
	av_dict_set(&opts, "strict", "experimental", 0);
	if (avcodec_open2(audio_output_file->codec_ctx, audio_output_file->codec, &opts) < 0) {
		/*FIXME: if we enter here (set "mp2" as a codec and "200000" as a bitrate -> deadlock*/
		GF_LOG(GF_LOG_ERROR, GF_LOG_DASH, ("Cannot open output audio codec\n"));
		av_dict_free(&opts);
		return -1;
	}
	av_dict_free(&opts);

	audio_output_file->frame_bytes = audio_output_file->codec_ctx->frame_size * av_get_bytes_per_sample(DC_AUDIO_SAMPLE_FORMAT) * DC_AUDIO_NUM_CHANNELS;

#ifndef FF_API_AVFRAME_LAVC
	avcodec_get_frame_defaults(audio_output_file->aframe);
#else
	av_frame_unref(audio_output_file->aframe);
#endif


	audio_output_file->aframe->nb_samples = audio_output_file->codec_ctx->frame_size;

	if (avcodec_fill_audio_frame(audio_output_file->aframe, audio_output_file->codec_ctx->channels, audio_output_file->codec_ctx->sample_fmt,
	                             audio_output_file->adata_buf, audio_output_file->codec_ctx->frame_size * av_get_bytes_per_sample(audio_output_file->codec_ctx->sample_fmt) * audio_output_file->codec_ctx->channels, 1) < 0) {
		GF_LOG(GF_LOG_ERROR, GF_LOG_DASH, ("Fill audio frame failed\n"));
		return -1;
	}

	//audio_output_file->acc_samples = 0;

	return 0;
}