void
HTTPStackHelper::Destroy()
{
  if (NULL != m_pCStreamNetwork)
  {
    QTV_Delete(m_pCStreamNetwork);
    m_pCStreamNetwork = NULL;
  }
  if (m_ProxyServerName)
  {
    QTV_Free(m_ProxyServerName);
    m_ProxyServerName = NULL;
  }
}
/*
 * @brief: Creates an instance of the Stream Services Nekwork Object
 *
 * @return. Returns an instance of the Stream Network Object
 *
 */
CStreamNetwork *CStreamNetwork::CreateInstance
(
 bool /*bPersistentConnection*/
)
{
  CStreamNetwork *pSTREAMNet = NULL;
  int result = 1;
  pSTREAMNet = QTV_New_Args(CStreamNetworkBSD, (result));

  if ( pSTREAMNet && result != 0 )
  {
    QTV_Delete(pSTREAMNet);
    pSTREAMNet = NULL;
  }

  return pSTREAMNet;
}
/** @brief PlaylistDownloadHelper Destructor.
*
*/
PlaylistDownloadHelper::~PlaylistDownloadHelper()
{
  if (m_pHTTPStack && bIsStackLocallyAllocated)
  {
    QTV_Delete(m_pHTTPStack);
    m_pHTTPStack = NULL;
  }
  if(m_RepresentationBuffer)
  {
    QTV_Free(m_RepresentationBuffer);
    m_RepresentationBuffer = NULL;
  }
  if (m_pLaunchURL)
  {
    QTV_Free(m_pLaunchURL);
    m_pLaunchURL = NULL;
  }
}
struct VDecoder *vdec_open(struct vdec_context *ctxt)
{
  struct VDecoder *dec = NULL;
  VDEC_ERROR err = 0;
  const VDEC_CONCURRENCY_CONFIG concurrencyConfig = VDEC_CONCURRENT_NONE;
  VideoDecoder* pDec = NULL;
  dec = (VDecoder*)calloc(1, sizeof(struct VDecoder));
  if (!dec) { 
    return 0;
  }
  dec->ctxt = ctxt;
  dec->width = ctxt->width;
  dec->height = ctxt->height;
  dec->ctxt->outputBuffer.numBuffers = ctxt->outputBuffer.numBuffers;
  if(VDEC_SUCCESS != vdec_commit_memory(dec)) {	
    return 0;
  }

  QPERF_RESET(arm_decode);
  QPERF_RESET(frame_data);
  nFrameDoneCnt = 0;
  nGoodFrameCnt = 0;
#ifdef PROFILE_DECODER
  qperf_total_frame_cnt = 0;
#endif

  vdec_output_frame_index = 0;
  timestamp = 0;
  int i;
  VDEC_PARAMETER_DATA codeDetectionEnable;
  codeDetectionEnable.startCodeDetection.bStartCodeDetectionEnable = false; // by default set to false; MPEG4 doesnt require it

  QTV_MSG_PRIO2(QTVDIAG_GENERAL,QTVDIAG_PRIO_LOW,"vdec: vdec_open(). width: %d, height: %d\n", dec->width, dec->height);

  vdec_decoder_info = dec;
  QTV_MSG_PRIO3(QTVDIAG_GENERAL,QTVDIAG_PRIO_LOW,"vdec: vdec_open(). width: %d, height: %d kind[%s]\n", 
                                                   vdec_decoder_info->ctxt->width, vdec_decoder_info->ctxt->height, 
                                                   vdec_decoder_info->ctxt->kind);

  if(!strcmp(vdec_decoder_info->ctxt->kind,"OMX.qcom.video.decoder.avc"))
  {
	dec->core = reinterpret_cast<VDEC_STREAM_ID>(pCreateFnH264(&err));
	QTV_MSG_PRIO1(QTVDIAG_GENERAL,QTVDIAG_PRIO_LOW,"vdec: Creating H264 Decoder [%p]\n",dec->core);
	VDEC_PARAMETER_DATA sizeOfNalLengthField;
        sizeOfNalLengthField.sizeOfNalLengthField.sizeOfNalLengthField = dec->ctxt->size_of_nal_length_field;
		QTV_MSG_PRIO1(QTVDIAG_GENERAL,QTVDIAG_PRIO_LOW,"vdec: NAL lenght [%d]\n",dec->ctxt->size_of_nal_length_field);
        pDec = (VideoDecoder*)(dec->core);
        if (0 == dec->ctxt->size_of_nal_length_field) 
        {
		   QTV_MSG_PRIO(QTVDIAG_GENERAL,QTVDIAG_PRIO_LOW,"vdec: START CODE....\n");
	       codeDetectionEnable.startCodeDetection.bStartCodeDetectionEnable = true;
		   if(!pDec) 
	          err = VDEC_ERR_NULL_STREAM_ID;
	       else
		      err = pDec->SetParameter(VDEC_PARM_START_CODE_DETECTION,&codeDetectionEnable);
           if (VDEC_ERR_EVERYTHING_FINE != err)
           {
		      // TBD- printx("[vdec_core] set start code detection parameter failed: %d", (int)err);
		      QTV_MSG_PRIO1(QTVDIAG_GENERAL,QTVDIAG_PRIO_ERROR,"[vdec_core] set start code detection parameter failed: %d", (int)err);
              goto fail_initialize;
           }
        }
        else if(dec->ctxt->size_of_nal_length_field > 0 && dec->ctxt->size_of_nal_length_field <= 4)
        {
			QTV_MSG_PRIO1(QTVDIAG_GENERAL,QTVDIAG_PRIO_ERROR,"vdec: NALU LENGTH[%d]\n",dec->ctxt->size_of_nal_length_field);
           // test size of NAL length field decoder support 
	       if(!pDec) 
	          err = VDEC_ERR_NULL_STREAM_ID;
	       else
             err = pDec->SetParameter( VDEC_PARM_SIZE_OF_NAL_LENGTH_FIELD, &sizeOfNalLengthField );
	       if (VDEC_ERR_EVERYTHING_FINE != err)
           {
             // TBD- printx("[vdec_core] set start code detection parameter failed: %d", (int)err);
             goto fail_initialize;
           }
	    }
	    else
        {
			QTV_MSG_PRIO1(QTVDIAG_GENERAL,QTVDIAG_PRIO_ERROR,"vdec: Invalid size of nal length field: %d\n", dec->ctxt->size_of_nal_length_field);
            goto fail_core;
        } 
  }
  else if ((!strcmp(vdec_decoder_info->ctxt->kind,"OMX.qcom.video.decoder.mpeg4")) 
	       || (!strcmp(vdec_decoder_info->ctxt->kind,"OMX.qcom.video.decoder.h263")))
  {
	  dec->core = reinterpret_cast<VDEC_STREAM_ID>(pCreateFnMpeg4(&err));
	  pDec = (VideoDecoder*)(dec->core);
	  QTV_MSG_PRIO1(QTVDIAG_GENERAL,QTVDIAG_PRIO_LOW,"vdec: Creating MP4 Decoder [%p]\n",dec->core);
  }
  else if (!strcmp(vdec_decoder_info->ctxt->kind,"OMX.qcom.video.decoder.vc1"))
  {
	  dec->core = reinterpret_cast<VDEC_STREAM_ID>(pCreateFnWmv(&err));
	  pDec = (VideoDecoder*)(dec->core);
	  QTV_MSG_PRIO1(QTVDIAG_GENERAL,QTVDIAG_PRIO_LOW,"vdec: Creating WMV Decoder [%p]\n",dec->core);
  }
  else
  { 
	QTV_MSG_PRIO(QTVDIAG_GENERAL,QTVDIAG_PRIO_ERROR,"Incorrect codec kind\n");
    goto fail_core;
  }

  if (VDEC_ERR_EVERYTHING_FINE != err || NULL == dec->core)
  {
	  QTV_MSG_PRIO(QTVDIAG_GENERAL,QTVDIAG_PRIO_ERROR,"vdec: create failed\n");
      goto fail_core;
  }

  for(i=0; i<VDEC_NFRAMES; i++)
  {
    slice_buffer_info[i].base = (char*)dec->input[i].base;
    //slice_buffer_info[i].phys = dec->input[i].phys;
    slice_buffer_info[i].fd = dec->input[i].pmem_id;
  }
  
  VDEC_DIMENSIONS frameSize;
  frameSize.height = dec->height;
  frameSize.width = dec->width;
  QTV_MSG_PRIO2(QTVDIAG_GENERAL,QTVDIAG_PRIO_HIGH,"vdec: Init width: %d height %d\n", frameSize.width, frameSize.height);

/*  
  VDEC_PARAMETER_DATA deblockerInfo;
  deblockerInfo.deblockerEnable.bDeblockerEnable = true;

  QTV_MSG_PRIO(QTVDIAG_GENERAL,QTVDIAG_PRIO_HIGH,"[vdec_core] SetParameter\n"); 
  err = vdec_set_parameter(dec->core, VDEC_PARM_DEBLOCKER_ENABLE, &deblockerInfo); 
  QTV_MSG_PRIO1(QTVDIAG_GENERAL,QTVDIAG_PRIO_HIGH,"[vdec_core] after SetParameter\n",err); 
  if (VDEC_ERR_EVERYTHING_FINE != err)
  {
    //TBD - printx("[vdec_core] set deblocker enable parameter failed: %d", (int)err);
    goto fail_initialize;
  }
*/

 
  QTV_MSG_PRIO(QTVDIAG_GENERAL,QTVDIAG_PRIO_HIGH,"vdec: vdec_initialize\n"); 
  if(!pDec) 
	  err = VDEC_ERR_NULL_STREAM_ID;
  else
  {
      err = pDec->Initialize(1,
			                 vdec_frame_buffer_malloc_cb_handler,
				             vdec_frame_buffer_free_cb_handler,
                             vdec_frame_cb_handler,
				             NULL,
				             frameSize,
				             VDEC_CONCURRENT_NONE,
				             slice_buffer_info,
					     dec->ctxt->outputBuffer.numBuffers,
					     ctxt->adsp_fd);
  }

  QTV_MSG_PRIO1(QTVDIAG_GENERAL,QTVDIAG_PRIO_HIGH,"vdec: vdec_initialize\n",err); 
  if (err != VDEC_ERR_EVERYTHING_FINE)
  {
	  QTV_MSG_PRIO1(QTVDIAG_GENERAL,QTVDIAG_PRIO_ERROR,"vdec: initialization failed: %d\n", (int)err);
      goto fail_initialize;
  }

#if NEED_VDEC_LP
#ifdef _ANDROID_
  dec->fake = adsp_open("/dev/adsp/VDEC_LP_MODE", dec->core, core_msg_func);
#else
  dec->fake = adsp_open("/dev/VDEC_LP_MODE", dec->core, core_msg_func);
#endif //_ANDROID_
  if (!dec->fake)
  {
	  QTV_MSG_PRIO1(QTVDIAG_GENERAL,QTVDIAG_PRIO_ERROR,"vdec: adsp_open() failed error: %s\n", strerror(errno));
    goto fail_initialize;
  }
  if (adsp_enable((adsp_module*)dec->fake)) goto fail_enable;
#endif

#ifdef LOG_YUV_FRAMES
#ifdef T_WINNT
  pYUVFile = fopen ( "../debug/yuvframes.yuv" , "wb" );
#elif _ANDROID_
  pYUVFile = fopen ( "/data/yuvframes.yuv" , "wb" );
#else
  pYUVFile = fopen ( "yuvframes.yuv" , "wb" );
#endif
#endif

#ifdef LOG_INPUT_BUFFERS
#ifdef T_WINNT
  pInputFile = fopen ( "../debug/inputbuffers.bin" , "wb" );
#elif _ANDROID_
  pInputFile = fopen ( "/data/inputbuffers.bin" , "wb" );
#else
  pInputFile = fopen ( "inputbuffers.bin" , "wb" );
#endif
#endif

  return dec;
fail_enable:
#if NEED_VDEC_LP
  adsp_close((adsp_module*)dec->fake);
#endif
fail_initialize:
  if(pDec) {
	  pDec->Suspend( );
	  QTV_Delete( pDec );
  }
fail_core:
  if (dec) {
    dec->dead = 1;
    free(dec);
  }
  return NULL;

}
Vdec_ReturnType vdec_close(struct VDecoder *dec)
{
  VDEC_ERROR err;
  VideoDecoder* pDec = (VideoDecoder*)(dec->core);
  QTV_MSG_PRIO(QTVDIAG_GENERAL,QTVDIAG_PRIO_LOW,"vdec: vdec_close()\n");
#ifdef PROFILE_DECODER
  usecs_t time_taken_by_arm = QPERF_TERMINATE(arm_decode);
  float avArmTime = (float)time_taken_by_arm/(qperf_total_frame_cnt*1000);
  usecs_t frame_data_time = QPERF_TERMINATE(frame_data);
  QTV_PERF_MSG_PRIO(QTVDIAG_GENERAL,QTVDIAG_PRIO_FATAL,"===========================================================\n");
  QTV_PERF_MSG_PRIO(QTVDIAG_GENERAL,QTVDIAG_PRIO_FATAL,"                     Arm Statistics                        \n");
  QTV_PERF_MSG_PRIO(QTVDIAG_GENERAL,QTVDIAG_PRIO_FATAL,"===========================================================\n");
  QTV_PERF_MSG_PRIO1(QTVDIAG_GENERAL,QTVDIAG_PRIO_FATAL,"Total number of frames decoded = %ld\n",qperf_total_frame_cnt);
  QTV_PERF_MSG_PRIO1(QTVDIAG_GENERAL,QTVDIAG_PRIO_FATAL,"Average Arm time/frame(ms)     = %f\n",avArmTime);
  QTV_PERF_MSG_PRIO1(QTVDIAG_GENERAL,QTVDIAG_PRIO_FATAL,"Frames Arm Decoded/sec         = %f\n",1000/avArmTime);
  QTV_PERF_MSG_PRIO(QTVDIAG_GENERAL,QTVDIAG_PRIO_FATAL,"===========================================================\n");
  QTV_PERF_MSG_PRIO(QTVDIAG_GENERAL,QTVDIAG_PRIO_FATAL,"                    Frame Done Statistics                  \n");
  QTV_PERF_MSG_PRIO(QTVDIAG_GENERAL,QTVDIAG_PRIO_FATAL,"===========================================================\n");
  QTV_PERF_MSG_PRIO1(QTVDIAG_GENERAL,QTVDIAG_PRIO_FATAL,"Frame done cumulative time     = %lld\n",frame_data_time);
  QTV_PERF_MSG_PRIO1(QTVDIAG_GENERAL,QTVDIAG_PRIO_FATAL,"Frames Done per second         = %f\n",(float)(qperf_total_frame_cnt-1)*1000000/frame_data_time);
  QTV_PERF_MSG_PRIO(QTVDIAG_GENERAL,QTVDIAG_PRIO_FATAL,"===========================================================\n");
#endif
#ifdef LOG_YUV_FRAMES
  if (pYUVFile)
  {
    fclose (pYUVFile);
	pYUVFile = NULL;
  }
#endif
#ifdef LOG_INPUT_BUFFERS
  if (pInputFile)
  {
    fclose (pInputFile);
  }
#endif
  vdec_output_frame_index = 0;

#if NEED_VDEC_LP
  if (vdec->fake)
  {
    //jlk - adsp_close() calls adsp_disable right now.  Calling adsp_disable() twice causes problems
    //Renable this line when we fix the kernel driver
    //adsp_disable((adsp_module*)vdec->fake);
    adsp_close((adsp_module*)vdec->fake);
  }
  else
  {
	  QTV_MSG_PRIO(QTVDIAG_GENERAL,QTVDIAG_PRIO_HIGH,"vdec: adsp modules is NULL\n");
  }
#endif
  nFrameDoneCnt = 0;
  nGoodFrameCnt = 0;

  if (dec->core)
  {
	QTV_MSG_PRIO(QTVDIAG_GENERAL,QTVDIAG_PRIO_LOW,"vdec: calling Suspend");
    err = pDec->Suspend( );
    if (VDEC_ERR_EVERYTHING_FINE != err)
    {
		QTV_MSG_PRIO1(QTVDIAG_GENERAL,QTVDIAG_PRIO_ERROR,"vdec: Suspend returned error: %d\n", (int)err);
    }
	QTV_MSG_PRIO(QTVDIAG_GENERAL,QTVDIAG_PRIO_LOW,"vdec: calling vdec_destroy"); 
	QTV_Delete( (VideoDecoder*)(dec->core) );
  }
  else
  {
	  QTV_MSG_PRIO(QTVDIAG_GENERAL,QTVDIAG_PRIO_HIGH,"vdec: core is NULL");
  }
    pmem_free(&dec->arena);
	free(dec);
	QTV_MSG_PRIO(QTVDIAG_GENERAL,QTVDIAG_PRIO_MED,"vdec: closed\n");
	return VDEC_SUCCESS;
}