static void dec_init(MSFilter *f){ AMediaFormat *format; AMediaCodec *codec = AMediaCodec_createDecoderByType("video/avc"); DecData *d=ms_new0(DecData,1); d->codec = codec; d->sps=NULL; d->pps=NULL; rfc3984_init(&d->unpacker); d->packet_num=0; d->vsize.width=0; d->vsize.height=0; d->bitstream_size=65536; d->avpf_enabled=FALSE; d->bitstream=ms_malloc0(d->bitstream_size); d->buf_allocator = ms_yuv_buf_allocator_new(); ms_average_fps_init(&d->fps, " H264 decoder: FPS: %f"); format = AMediaFormat_new(); AMediaFormat_setString(format,"mime","video/avc"); //Size mandatory for decoder configuration AMediaFormat_setInt32(format,"width",1920); AMediaFormat_setInt32(format,"height",1080); AMediaCodec_configure(codec, format, NULL, NULL, 0); AMediaCodec_start(codec); AMediaFormat_delete(format); f->data=d; }
void initMediaFormat(MCDec *ctx, AMediaFormat *format) { AMediaFormat_setString(ctx->format, AMEDIAFORMAT_KEY_MIME, ctx->mime); AMediaFormat_setInt32(ctx->format, AMEDIAFORMAT_KEY_WIDTH, ctx->width); AMediaFormat_setInt32(ctx->format, AMEDIAFORMAT_KEY_HEIGHT, ctx->height); AMediaFormat_setInt32(ctx->format, AMEDIAFORMAT_KEY_STRIDE, ctx->stride); AMediaFormat_setInt32(ctx->format, AMEDIAFORMAT_KEY_MAX_INPUT_SIZE, ctx->width * ctx->height); }
static void enc_preprocess(MSFilter* f) { EncData *d=(EncData*)f->data; d->packer=rfc3984_new(); rfc3984_set_mode(d->packer,d->mode); rfc3984_enable_stap_a(d->packer,FALSE); ms_video_starter_init(&d->starter); AMediaCodec *codec; codec = AMediaCodec_createEncoderByType("video/avc"); d->codec = codec; AMediaFormat *format = AMediaFormat_new(); AMediaFormat_setString(format, "mime", "video/avc"); AMediaFormat_setInt32(format, "width", d->vconf.vsize.width); AMediaFormat_setInt32(format, "height", d->vconf.vsize.height); AMediaFormat_setInt32(format, "i-frame-interval", 20); AMediaFormat_setInt32(format, "color-format", 19); AMediaFormat_setInt32(format, "bitrate", d->vconf.required_bitrate); AMediaFormat_setInt32(format, "frame-rate", d->vconf.fps); AMediaFormat_setInt32(format, "bitrate-mode",1); media_status_t status = AMediaCodec_configure(d->codec, format, NULL, NULL, AMEDIACODEC_CONFIGURE_FLAG_ENCODE); if(status != 0){ d->isYUV = FALSE; AMediaFormat_setInt32(format, "color-format", 21); AMediaCodec_configure(d->codec, format, NULL, NULL, AMEDIACODEC_CONFIGURE_FLAG_ENCODE); } AMediaCodec_start(d->codec); AMediaFormat_delete(format); }
static void dec_reinit(DecData *d){ AMediaFormat *format; AMediaCodec_flush(d->codec); AMediaCodec_stop(d->codec); AMediaCodec_delete(d->codec); ms_message("Restart dec"); d->codec = AMediaCodec_createDecoderByType("video/avc"); format = AMediaFormat_new(); AMediaFormat_setString(format,"mime","video/avc"); //Size mandatory for decoder configuration AMediaFormat_setInt32(format,"width",1920); AMediaFormat_setInt32(format,"height",1080); AMediaCodec_configure(d->codec, format, NULL, NULL, 0); AMediaCodec_start(d->codec); AMediaFormat_delete(format); }