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;
}
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);
}
示例#3
0
static GF_Err MCDec_InitDecoder(MCDec *ctx) {

    GF_Err err;
    ctx->format = AMediaFormat_new();

    if(!ctx->format) {
         GF_LOG(GF_LOG_ERROR, GF_LOG_CODEC,("AMediaFormat_new failed"));
        return GF_CODEC_NOT_FOUND;
    }

    ctx->pix_fmt = GF_PIXEL_NV12;

    switch (ctx->esd->decoderConfig->objectTypeIndication) {

        case GPAC_OTI_VIDEO_AVC :
            err = MCDec_InitAvcDecoder(ctx);
            break;

        case GPAC_OTI_VIDEO_MPEG4_PART2 :
            err = MCDec_InitMpeg4Decoder(ctx);            
            break;
            
        case GPAC_OTI_VIDEO_HEVC:
            err = MCDec_InitHevcDecoder(ctx);
            break;
     
        default:
            return GF_NOT_SUPPORTED;
    }

    if(err != GF_OK){
        return err;
    }

    ctx->frame_rate = 50.0f;
    ctx->dequeue_timeout = 5000;
    ctx->stride = ctx->width;
    initMediaFormat(ctx, ctx->format);

    ctx->codec = AMediaCodec_createDecoderByType(ctx->mime);

    if(!ctx->codec) {
         GF_LOG(GF_LOG_ERROR, GF_LOG_CODEC,("AMediaCodec_createDecoderByType failed"));
        return GF_CODEC_NOT_FOUND;
    }
    
    if(!ctx->window) 
		MCDec_CreateSurface(&ctx->window,&ctx->gl_tex_id, &ctx->surface_rendering);

    if( AMediaCodec_configure(
        ctx->codec, // codec   
        ctx->format, // format
        (ctx->surface_rendering) ? ctx->window : NULL,  //surface 
        NULL, // crypto 
        0 // flags 
        )     != AMEDIA_OK) 
    {
         GF_LOG(GF_LOG_ERROR, GF_LOG_CODEC,("AMediaCodec_configure failed"));
        return GF_BAD_PARAM;
    }

    if( AMediaCodec_start(ctx->codec) != AMEDIA_OK){
         GF_LOG(GF_LOG_ERROR, GF_LOG_CODEC,("AMediaCodec_start failed"));
        return GF_BAD_PARAM;
    } 
	
	ctx->inputEOS = GF_FALSE;
    ctx->outputEOS = GF_FALSE;
	 GF_LOG(GF_LOG_INFO, GF_LOG_CODEC,("Video size: %d x %d", ctx->width, ctx->height));
    return GF_OK;
}
jboolean Java_com_example_nativecodec_NativeCodec_createStreamingMediaPlayer(JNIEnv *env,
                                                                             jclass clazz,
                                                                             jstring filename)
{
   LOGV("@@@ create");

   // convert Java string to UTF-8
   const char *utf8 = env->GetStringUTFChars(filename, NULL);
   LOGV("opening %s", utf8);
   int fd = open(utf8, O_RDONLY);
   env->ReleaseStringUTFChars(filename, utf8);
   if (fd < 0)
   {
      LOGV("failed: %d (%s)", fd, strerror(errno));
      return JNI_FALSE;
   }

   data.fd = fd;

   workerdata *d = &data;

   AMediaExtractor *ex = AMediaExtractor_new();
   media_status_t err = AMediaExtractor_setDataSourceFd(ex, d->fd, 0, LONG_MAX);
   close(d->fd);
   if (err != AMEDIA_OK)
   {
      LOGV("setDataSource error: %d", err);
      return JNI_FALSE;
   }

   int numtracks = AMediaExtractor_getTrackCount(ex);

   AMediaCodec *codec = NULL;

   LOGV("input has %d tracks", numtracks);
   for (int i = 0; i < numtracks; i++)
   {
      AMediaFormat *format = AMediaExtractor_getTrackFormat(ex, i);
      const char *s = AMediaFormat_toString(format);
      LOGV("track %d format: %s", i, s);
      const char *mime;
      if (!AMediaFormat_getString(format, AMEDIAFORMAT_KEY_MIME, &mime))
      {
         LOGV("no mime type");
         return JNI_FALSE;
      }
      else if (!strncmp(mime, "video/", 6))
      {
         // Omitting most error handling for clarity.
         // Production code should check for errors.
         AMediaExtractor_selectTrack(ex, i);
         codec = AMediaCodec_createDecoderByType(mime);
         AMediaCodec_configure(codec, format, d->window, NULL, 0);
         d->ex = ex;
         d->codec = codec;
         d->renderstart = -1;
         d->sawInputEOS = false;
         d->sawOutputEOS = false;
         d->isPlaying = false;
         d->renderonce = true;
         AMediaCodec_start(codec);
      }
      AMediaFormat_delete(format);
   }

   mlooper = new mylooper();
   mlooper->post(kMsgCodecBuffer, d);

   return JNI_TRUE;
}