Exemplo n.º 1
0
/*
 * picture_to_frame reads and decodes
 * the picture file
 *
 * side effects: allocates an AVFrame which
 * must be freed with av_free_frame
 */
FFMPEG_tmp * picture_to_frame(char *filepath) {

    AVFormatContext *fctx = NULL;
    int              stream_no;
    AVCodecContext  *cctx = NULL;
    AVCodec         *c = NULL;
    AVFrame         *frame = NULL;

    FFMPEG_tmp      *tmp = malloc(sizeof(FFMPEG_tmp));

    fctx = get_fcontext(filepath);
    if (fctx == NULL) {
        fprintf(stderr, "Fatal: could not open %s\n", filepath);
        avformat_close_input(&fctx);
        exit(1);
    }

    stream_no = get_video_stream(fctx);
    if (stream_no == -1) {
        fprintf(stderr, "Fatal: could not find video stream\n");
        avformat_close_input(&fctx);
        exit(1);
    }

    cctx = get_ccontext(fctx, stream_no);
    if (cctx == NULL) {
        fprintf(stderr, "Fatal: no codec context initialized\n");
        avcodec_close(cctx);
        avformat_close_input(&fctx);
        exit(1);
    }

    c = get_codec(cctx);
    if (c == NULL) {
        fprintf(stderr, "Fatal: could not open codec\n");
        avcodec_close(cctx);
        avformat_close_input(&fctx);
        exit(1);
    }

    frame = decode_picture(fctx, stream_no, cctx);
    if (frame == NULL) {
        avcodec_close(cctx);
        avformat_close_input(&fctx);
        fprintf(stderr, "Fatal: could not decode image\n");
        exit(1);
    }

    /* clean up successful run */
    tmp->frame = frame;
    tmp->fctx = fctx;
    tmp->cctx = cctx;
    tmp->c = c;

    return tmp;
}
Exemplo n.º 2
0
static av_cold int encode_init(AVCodecContext *avctx)
{
    CombineContext *c= avctx->priv_data;
    int ret;
    int offset= (uint8_t*)&c->options - (uint8_t*)c;

    c->codec= get_codec(avctx->sample_fmt);
    if(!c->codec){
        av_log(avctx, AV_LOG_ERROR, "Unsupported sample format\n");
        return -1;
    }
    c->ctx= av_mallocz(c->codec->priv_data_size);
    memcpy((uint8_t*)c->ctx + offset, &c->options, (uint8_t*)&c->ctx - (uint8_t*)&c->options);
    FFSWAP(void *,avctx->priv_data, c->ctx);
    ret= c->codec->init(avctx);
    FFSWAP(void *,avctx->priv_data, c->ctx);
    return ret;
}
Exemplo n.º 3
0
static int audio_open(const hw_module_t *module, const char *name,
							hw_device_t **device)
{
	struct a2dp_audio_dev *a2dp_dev;
	size_t i;
	int err;

	DBG("");

	if (strcmp(name, AUDIO_HARDWARE_INTERFACE)) {
		error("audio: interface %s not matching [%s]", name,
						AUDIO_HARDWARE_INTERFACE);
		return -EINVAL;
	}

	err = audio_ipc_init();
	if (err < 0)
		return err;

	a2dp_dev = calloc(1, sizeof(struct a2dp_audio_dev));
	if (!a2dp_dev)
		return -ENOMEM;

	a2dp_dev->dev.common.tag = HARDWARE_DEVICE_TAG;
	a2dp_dev->dev.common.version = AUDIO_DEVICE_API_VERSION_CURRENT;
	a2dp_dev->dev.common.module = (struct hw_module_t *) module;
	a2dp_dev->dev.common.close = audio_close;

	a2dp_dev->dev.init_check = audio_init_check;
	a2dp_dev->dev.set_voice_volume = audio_set_voice_volume;
	a2dp_dev->dev.set_master_volume = audio_set_master_volume;
	a2dp_dev->dev.set_mode = audio_set_mode;
	a2dp_dev->dev.set_mic_mute = audio_set_mic_mute;
	a2dp_dev->dev.get_mic_mute = audio_get_mic_mute;
	a2dp_dev->dev.set_parameters = audio_set_parameters;
	a2dp_dev->dev.get_parameters = audio_get_parameters;
	a2dp_dev->dev.get_input_buffer_size = audio_get_input_buffer_size;
	a2dp_dev->dev.open_output_stream = audio_open_output_stream;
	a2dp_dev->dev.close_output_stream = audio_close_output_stream;
	a2dp_dev->dev.open_input_stream = audio_open_input_stream;
	a2dp_dev->dev.close_input_stream = audio_close_input_stream;
	a2dp_dev->dev.dump = audio_dump;

	loaded_codecs = queue_new();

	for (i = 0; i < NUM_CODECS; i++) {
		audio_codec_get_t get_codec = audio_codecs[i];
		const struct audio_codec *codec = get_codec();

		if (codec->load && !codec->load())
			continue;

		queue_push_tail(loaded_codecs, (void *) codec);
	}

	/*
	 * Note that &a2dp_dev->dev.common is the same pointer as a2dp_dev.
	 * This results from the structure of following structs:a2dp_audio_dev,
	 * audio_hw_device. We will rely on this later in the code.
	 */
	*device = &a2dp_dev->dev.common;

	return 0;
}