コード例 #1
0
static gboolean gst_openh264dec_start(GstVideoDecoder *decoder)
{
    GstOpenh264Dec *openh264dec = GST_OPENH264DEC(decoder);
    gint ret;
    SDecodingParam dec_param = {0};

    if (openh264dec->priv->decoder != NULL)
    {
        openh264dec->priv->decoder->Uninitialize();
        WelsDestroyDecoder(openh264dec->priv->decoder);
        openh264dec->priv->decoder = NULL;
    }
    WelsCreateDecoder(&(openh264dec->priv->decoder));

    dec_param.uiTargetDqLayer = 255;
    dec_param.uiEcActiveFlag = 1;
    dec_param.iOutputColorFormat = videoFormatI420;
    dec_param.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_AVC;

    ret = openh264dec->priv->decoder->Initialize(&dec_param);

    GST_DEBUG_OBJECT(openh264dec, "openh264_dec_start called, openh264dec %sinitialized OK!", (ret != cmResultSuccess) ? "NOT " : "");

    return (ret == cmResultSuccess);
}
コード例 #2
0
ファイル: h264.c プロジェクト: CoryXie/FreeRDP
H264_CONTEXT* h264_context_new(BOOL Compressor)
{
	H264_CONTEXT* h264;

	h264 = (H264_CONTEXT*) calloc(1, sizeof(H264_CONTEXT));

	if (h264)
	{
		h264->Compressor = Compressor;

#ifdef WITH_OPENH264
		{
			static EVideoFormatType videoFormat = videoFormatI420;

			SDecodingParam sDecParam;
			long status;

			WelsCreateDecoder(&h264->pDecoder);

			if (!h264->pDecoder)
			{
				printf("Failed to create OpenH264 decoder\n");
				goto EXCEPTION;
			}

			ZeroMemory(&sDecParam, sizeof(sDecParam));
			sDecParam.iOutputColorFormat = videoFormatARGB;
			status = (*h264->pDecoder)->Initialize(h264->pDecoder, &sDecParam);
			if (status != 0)
			{
				printf("Failed to initialize OpenH264 decoder (status=%ld)\n", status);
				goto EXCEPTION;
			}

			status = (*h264->pDecoder)->SetOption(h264->pDecoder, DECODER_OPTION_DATAFORMAT, &videoFormat);
			if (status != 0)
			{
				printf("Failed to set data format option on OpenH264 decoder (status=%ld)\n", status);
			}
		}
#endif
			
		h264_context_reset(h264);
	}

	return h264;

EXCEPTION:
#ifdef WITH_OPENH264
	if (h264->pDecoder)
	{
		WelsDestroyDecoder(h264->pDecoder);
	}
#endif

	free(h264);

	return NULL;
}
コード例 #3
0
MSOpenH264Decoder::MSOpenH264Decoder(MSFilter *f)
    : mFilter(f), mDecoder(0), mUnpacker(0), mSPS(0), mPPS(0), mYUVMsg(0),
      mBitstream(0), mBitstreamSize(65536), mLastErrorReportTime(0),
      mWidth(MS_VIDEO_SIZE_UNKNOWN_W), mHeight(MS_VIDEO_SIZE_UNKNOWN_H),
      mInitialized(false), mFirstImageDecoded(false)
{
    long ret = WelsCreateDecoder(&mDecoder);
    if (ret != 0) {
        ms_error("OpenH264 decoder: Failed to create decoder: %li", ret);
    } else {
        mBitstream = static_cast<uint8_t *>(ms_malloc0(mBitstreamSize));
    }
}
コード例 #4
0
waptestDecH264::waptestDecH264() {
  long rv = WelsCreateDecoder (&decoder_);
  ASSERT_EQ (0, rv);
  ASSERT_TRUE (decoder_ != NULL);

  SDecodingParam decParam;
  memset (&decParam, 0, sizeof (SDecodingParam));
  decParam.eOutputColorFormat  = videoFormatI420;
  decParam.uiTargetDqLayer = UCHAR_MAX;
  decParam.eEcActiveIdc = ERROR_CON_SLICE_COPY;
  decParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;

  rv = decoder_->Initialize (&decParam);
  ASSERT_EQ (0, rv);
}
コード例 #5
0
ファイル: BaseDecoderTest.cpp プロジェクト: cisco/openh264
int32_t BaseDecoderTest::SetUp() {
  long rv = WelsCreateDecoder (&decoder_);
  EXPECT_EQ (0, rv);
  EXPECT_TRUE (decoder_ != NULL);
  if (decoder_ == NULL) {
    return rv;
  }

  SDecodingParam decParam;
  memset (&decParam, 0, sizeof (SDecodingParam));
  decParam.uiTargetDqLayer = UCHAR_MAX;
  decParam.eEcActiveIdc = ERROR_CON_SLICE_COPY;
  decParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;

  rv = decoder_->Initialize (&decParam);
  EXPECT_EQ (0, rv);
  return (int32_t)rv;
}
コード例 #6
0
  virtual void InitDecode (const GMPVideoCodec& codecSettings,
                           const uint8_t* aCodecSpecific,
                           uint32_t aCodecSpecificSize,
                           GMPVideoDecoderCallback* callback,
                           int32_t coreCount) {
    callback_ = callback;

    GMPLOG (GL_INFO, "InitDecode");

    GMPErr err = g_platform_api->createthread (&worker_thread_);
    if (err != GMPNoErr) {
      GMPLOG (GL_ERROR, "Couldn't create new thread");
      Error (GMPGenericErr);
      return;
    }

    if (WelsCreateDecoder (&decoder_)) {
      GMPLOG (GL_ERROR, "Couldn't create decoder");
      Error (GMPGenericErr);
      return;
    }

    if (!decoder_) {
      GMPLOG (GL_ERROR, "Couldn't create decoder");
      Error (GMPGenericErr);
      return;
    }

    SDecodingParam param;
    memset (&param, 0, sizeof (param));
    param.eOutputColorFormat = videoFormatI420;
    param.uiTargetDqLayer = UCHAR_MAX;  // Default value
    param.eEcActiveIdc = ERROR_CON_SLICE_COPY; // Error concealment on.
    param.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;

    if (decoder_->Initialize (&param)) {
      GMPLOG (GL_ERROR, "Couldn't initialize decoder");
      Error (GMPGenericErr);
      return;
    }
  }
コード例 #7
0
ファイル: libopenh264dec.c プロジェクト: Emerica/FFmpeg
static av_cold int svc_decode_init(AVCodecContext *avctx)
{
    SVCContext *s = avctx->priv_data;
    SDecodingParam param = { 0 };
    int err;
    int log_level;
    WelsTraceCallback callback_function;

    if ((err = ff_libopenh264_check_version(avctx)) < 0)
        return err;

    if (WelsCreateDecoder(&s->decoder)) {
        av_log(avctx, AV_LOG_ERROR, "Unable to create decoder\n");
        return AVERROR_UNKNOWN;
    }

    // Pass all libopenh264 messages to our callback, to allow ourselves to filter them.
    log_level = WELS_LOG_DETAIL;
    callback_function = ff_libopenh264_trace_callback;
    (*s->decoder)->SetOption(s->decoder, DECODER_OPTION_TRACE_LEVEL, &log_level);
    (*s->decoder)->SetOption(s->decoder, DECODER_OPTION_TRACE_CALLBACK, (void *)&callback_function);
    (*s->decoder)->SetOption(s->decoder, DECODER_OPTION_TRACE_CALLBACK_CONTEXT, (void *)&avctx);

#if !OPENH264_VER_AT_LEAST(1, 6)
    param.eOutputColorFormat = videoFormatI420;
#endif
    param.eEcActiveIdc       = ERROR_CON_DISABLE;
    param.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;

    if ((*s->decoder)->Initialize(s->decoder, &param) != cmResultSuccess) {
        av_log(avctx, AV_LOG_ERROR, "Initialize failed\n");
        return AVERROR_UNKNOWN;
    }

    avctx->pix_fmt = AV_PIX_FMT_YUV420P;

    return 0;
}
コード例 #8
0
ファイル: decoder.cpp プロジェクト: rq4w7z/openh264-js
void * open_decoder(void)
{
    ISVCDecoder* decoder_ = NULL;
    if ( WelsCreateDecoder (&decoder_) ) {
        emscripten_log(EM_LOG_CONSOLE, "Create Decoder failed\n");
        return NULL;
    }
    if (! decoder_) {
        emscripten_log(EM_LOG_CONSOLE, "Create Decoder failed (no handle)\n");
        return NULL;
    }

    WelsTraceCallback cb = openh264_log;
    int32_t tracelevel = 3;//0x7fffffff;
    if ( decoder_->SetOption(DECODER_OPTION_TRACE_CALLBACK, (void*)&cb) )
    {
        emscripten_log(EM_LOG_CONSOLE, "SetOption failed\n");
    }
    if ( decoder_->SetOption(DECODER_OPTION_TRACE_LEVEL, &tracelevel) )
    {
        emscripten_log(EM_LOG_CONSOLE, "SetOption failed\n");
    }

    SDecodingParam decParam;
    memset (&decParam, 0, sizeof (SDecodingParam));
    decParam.eOutputColorFormat  = videoFormatI420;
    decParam.uiTargetDqLayer = UCHAR_MAX;
    decParam.eEcActiveIdc = ERROR_CON_SLICE_COPY;
    decParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;

    if ( decoder_->Initialize (&decParam) ) {
        emscripten_log(EM_LOG_CONSOLE, "initialize failed\n");
        return NULL;
    }

    return decoder_;
}
コード例 #9
0
ファイル: gmp-openh264.cpp プロジェクト: FAHADSUST/openh264
  virtual void InitDecode (const GMPVideoCodec& codecSettings,
                           const uint8_t* aCodecSpecific,
                           uint32_t aCodecSpecificSize,
                           GMPVideoDecoderCallback* callback,
                           int32_t coreCount) {
    callback_ = callback;

    GMPLOG (GL_INFO, "InitDecode");

    GMPErr err = g_platform_api->createthread (&worker_thread_);
    if (err != GMPNoErr) {
      GMPLOG (GL_ERROR, "Couldn't create new thread");
      Error (GMPGenericErr);
      return;
    }

    if (WelsCreateDecoder (&decoder_)) {
      GMPLOG (GL_ERROR, "Couldn't create decoder");
      Error (GMPGenericErr);
      return;
    }

    if (!decoder_) {
      GMPLOG (GL_ERROR, "Couldn't create decoder");
      Error (GMPGenericErr);
      return;
    }

    SDecodingParam param;
    memset (&param, 0, sizeof (param));
    param.uiTargetDqLayer = UCHAR_MAX;  // Default value
    param.eEcActiveIdc = ERROR_CON_SLICE_MV_COPY_CROSS_IDR_FREEZE_RES_CHANGE; // Error concealment on.
    param.sVideoProperty.size = sizeof(param.sVideoProperty);
    param.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;

    if (decoder_->Initialize (&param)) {
      GMPLOG (GL_ERROR, "Couldn't initialize decoder");
      Error (GMPGenericErr);
      return;
    }

    if (aCodecSpecific && aCodecSpecificSize >= sizeof(GMPVideoCodecH264)) {
      std::vector<uint8_t> annexb;

      // Convert the AVCC data, starting at the byte containing
      // numOfSequenceParameterSets, to Annex B format.
      const uint8_t* avcc = aCodecSpecific + offsetof(GMPVideoCodecH264, mAVCC.mNumSPS);

      static const int kSPSMask = (1 << 5) - 1;
      uint8_t spsCount = *avcc++ & kSPSMask;
      for (int i = 0; i < spsCount; ++i) {
        size_t size = readU16BE(avcc);
        avcc += 2;
        copyWithStartCode(annexb, avcc, size);
        avcc += size;
      }

      uint8_t ppsCount = *avcc++;
      for (int i = 0; i < ppsCount; ++i) {
        size_t size = readU16BE(avcc);
        avcc += 2;
        copyWithStartCode(annexb, avcc, size);
        avcc += size;
      }

      SBufferInfo decoded;
      memset (&decoded, 0, sizeof (decoded));
      unsigned char* data[3] = {nullptr, nullptr, nullptr};
      DECODING_STATE dState = decoder_->DecodeFrame2 (&*annexb.begin(),
                                                      annexb.size(),
                                                      data,
                                                      &decoded);
      if (dState) {
        GMPLOG (GL_ERROR, "Decoding error dState=" << dState);
      }
      GMPLOG (GL_ERROR, "InitDecode iBufferStatus=" << decoded.iBufferStatus);
    }
  }
コード例 #10
0
ファイル: h264.c プロジェクト: AMV007/FreeRDP
static BOOL openh264_init(H264_CONTEXT* h264)
{
	long status;
	SDecodingParam sDecParam;
	H264_CONTEXT_OPENH264* sys;
	static int traceLevel = WELS_LOG_DEBUG;
	static EVideoFormatType videoFormat = videoFormatI420;
	static WelsTraceCallback traceCallback = (WelsTraceCallback) openh264_trace_callback;

	sys = (H264_CONTEXT_OPENH264*) calloc(1, sizeof(H264_CONTEXT_OPENH264));

	if (!sys)
	{
		goto EXCEPTION;
	}

	h264->pSystemData = (void*) sys;

	if (h264->Compressor)
	{
		WelsCreateSVCEncoder(&sys->pEncoder);

		if (!sys->pEncoder)
		{
			WLog_ERR(TAG, "Failed to create OpenH264 encoder");
			goto EXCEPTION;
		}
	}
	else
	{
		WelsCreateDecoder(&sys->pDecoder);

		if (!sys->pDecoder)
		{
			WLog_ERR(TAG, "Failed to create OpenH264 decoder");
			goto EXCEPTION;
		}

		ZeroMemory(&sDecParam, sizeof(sDecParam));
		sDecParam.eOutputColorFormat  = videoFormatI420;
		sDecParam.eEcActiveIdc = ERROR_CON_FRAME_COPY;
		sDecParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;

		status = (*sys->pDecoder)->Initialize(sys->pDecoder, &sDecParam);

		if (status != 0)
		{
			WLog_ERR(TAG, "Failed to initialize OpenH264 decoder (status=%ld)", status);
			goto EXCEPTION;
		}

		status = (*sys->pDecoder)->SetOption(sys->pDecoder, DECODER_OPTION_DATAFORMAT, &videoFormat);

		if (status != 0)
		{
			WLog_ERR(TAG, "Failed to set data format option on OpenH264 decoder (status=%ld)", status);
		}

		if (g_openh264_trace_enabled)
		{
			status = (*sys->pDecoder)->SetOption(sys->pDecoder, DECODER_OPTION_TRACE_LEVEL, &traceLevel);

			if (status != 0)
			{
				WLog_ERR(TAG, "Failed to set trace level option on OpenH264 decoder (status=%ld)", status);
			}

			status = (*sys->pDecoder)->SetOption(sys->pDecoder, DECODER_OPTION_TRACE_CALLBACK, &traceCallback);

			if (status != 0)
			{
				WLog_ERR(TAG, "Failed to set trace callback option on OpenH264 decoder (status=%ld)", status);
			}

			status = (*sys->pDecoder)->SetOption(sys->pDecoder, DECODER_OPTION_TRACE_CALLBACK_CONTEXT, &h264);

			if (status != 0)
			{
				WLog_ERR(TAG, "Failed to set trace callback context option on OpenH264 decoder (status=%ld)", status);
			}
		}
	}

	return TRUE;

EXCEPTION:
	openh264_uninit(h264);

	return FALSE;
}