Esempio n. 1
0
static GF_Err HEVC_ProcessData(GF_MediaDecoder *ifcg,
                               char *inBuffer, u32 inBufferLength,
                               u16 ES_ID, u32 *CTS,
                               char *outBuffer, u32 *outBufferLength,
                               u8 PaddingBits, u32 mmlevel)
{
	GF_Err e;
	int got_pic;
	HEVCDec *ctx = (HEVCDec*) ifcg->privateStack;

	if (!inBuffer) {
		if ( libOpenHevcDecode(ctx->openHevcHandle, NULL, 0, 0) ) {
			return HEVC_flush_picture(ctx, outBuffer, outBufferLength, CTS);
		}
		//quick hack, we have an issue with openHEVC resuming after being flushed ...
		ctx->had_pic = GF_FALSE;
		libOpenHevcClose(ctx->openHevcHandle);
		ctx->openHevcHandle = NULL;
		ctx->is_init = GF_FALSE;
		HEVC_ConfigureStream(ctx, ctx->esd);

		return GF_OK;
	}

	if (!ES_ID) {
		*outBufferLength = 0;
		return GF_OK;
	}

	if (*outBufferLength < ctx->out_size) {
		*outBufferLength = ctx->out_size;
		return GF_BUFFER_TOO_SMALL;
	}

	*outBufferLength = 0;

	if (ctx->had_pic) {
		ctx->had_pic = GF_FALSE;
		return HEVC_flush_picture(ctx, outBuffer, outBufferLength, CTS);
	}
	ctx->dec_frames++;
	got_pic = libOpenHevcDecode(ctx->openHevcHandle, (u8 *) inBuffer, inBufferLength, *CTS);

	if (ctx->raw_out) fwrite((u8 *) inBuffer, 1, inBufferLength, ctx->raw_out);

	GF_LOG(GF_LOG_DEBUG, GF_LOG_CODEC, ("[HEVC Decoder] Decode CTS %d - size %d - got pic %d\n", *CTS, inBufferLength, got_pic));
	if (got_pic>0) {
		e = HEVC_flush_picture(ctx, outBuffer, outBufferLength, CTS);
		if (e) return e;
		got_pic = 0;
	}

	return GF_OK;
}
Esempio n. 2
0
static GF_Err HEVC_DetachStream(GF_BaseDecoder *ifcg, u16 ES_ID)
{
	HEVCDec *ctx = (HEVCDec*) ifcg->privateStack;

	if (ctx->openHevcHandle) {
		libOpenHevcClose(ctx->openHevcHandle);
		ctx->openHevcHandle = NULL;
	}
	ctx->is_init = GF_FALSE;
	ctx->width = ctx->height = ctx->out_size = 0;
	if (ctx->conv_buffer) gf_free(ctx->conv_buffer);
	ctx->conv_buffer = NULL;
	return GF_OK;
}
Esempio n. 3
0
static GF_Err HEVC_SetCapabilities(GF_BaseDecoder *ifcg, GF_CodecCapability capability)
{
	HEVCDec *ctx = (HEVCDec*) ifcg->privateStack;
	switch (capability.CapCode) {
	case GF_CODEC_DISPLAY_BPP:
		ctx->display_bpp = capability.cap.valueInt;
		return GF_OK;
	case GF_CODEC_WAIT_RAP:
		if (ctx->dec_frames) {
			//quick hack, we have an issue with openHEVC resuming after being flushed ...
			ctx->had_pic = GF_FALSE;
			libOpenHevcClose(ctx->openHevcHandle);
			ctx->openHevcHandle = NULL;
			ctx->is_init = GF_FALSE;
			HEVC_ConfigureStream(ctx, ctx->esd);
		}
		return GF_OK;
	case GF_CODEC_MEDIA_SWITCH_QUALITY:
	if (ctx->nb_layers==1) return GF_OK;
		/*switch up*/
		if (capability.cap.valueInt > 0) {
			libOpenHevcSetViewLayers(ctx->openHevcHandle, 1);
			libOpenHevcSetActiveDecoders(ctx->openHevcHandle, 1);
		} else {
			libOpenHevcSetViewLayers(ctx->openHevcHandle, 0);
			libOpenHevcSetActiveDecoders(ctx->openHevcHandle, 0);
		}
		return GF_OK;
	case GF_CODEC_RAW_MEMORY:
		ctx->direct_output = GF_TRUE;
		ctx->pack_mode = GF_FALSE;
		if (ctx->conv_to_8bit && ctx->out_size)
			ctx->conv_buffer = (char*)gf_realloc(ctx->conv_buffer, sizeof(char)*ctx->out_size);

		return GF_OK;
	}
	/*return unsupported to avoid confusion by the player (like color space changing ...) */
	return GF_NOT_SUPPORTED;

}