예제 #1
0
bool VideoOutputOpenGL::Init(int width, int height, float aspect, WId winid,
                             const QRect &win_rect, MythCodecID codec_id)
{
    QMutexLocker locker(&gl_context_lock);

    bool success = true;
    // FIXME Mac OS X overlay does not work with preview
    window.SetAllowPreviewEPG(true);
    gl_parent_win = winid;

    VideoOutput::Init(width, height, aspect, winid, win_rect, codec_id);

    SetProfile();
    InitPictureAttributes();
    success &= SetupContext();
    InitDisplayMeasurements(width, height, false);
    success &= CreateBuffers();
    success &= CreatePauseFrame();
    success &= SetupOpenGL();
    InitOSD();
    MoveResize();

    if (!success)
        TearDown();

    return success;
}
예제 #2
0
void CGSH_OpenGLAndroid::InitializeImpl()
{
	static const EGLint configAttribs[] = 
	{
		EGL_SURFACE_TYPE,			EGL_WINDOW_BIT,
		EGL_RENDERABLE_TYPE,		EGL_OPENGL_ES2_BIT,
		EGL_BLUE_SIZE,				8,
		EGL_GREEN_SIZE,				8,
		EGL_RED_SIZE,				8,
		EGL_NONE
	};

	static const EGLint contextAttribs[] =
	{
		EGL_CONTEXT_CLIENT_VERSION,		3,
		EGL_NONE
	};
	
	m_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
	eglInitialize(m_display, 0, 0);
	
	EGLint numConfigs = 0;
	eglChooseConfig(m_display, configAttribs, &m_config, 1, &numConfigs);
	assert(numConfigs > 0);
	
	m_context = eglCreateContext(m_display, m_config, NULL, contextAttribs);
	assert(m_context != EGL_NO_CONTEXT);

	SetupContext();
	
	CGSH_OpenGL::InitializeImpl();
}
예제 #3
0
bool VideoOutputOpenGL::CreateGPUResources(void)
{
    bool result = SetupContext();
    QSize size = window.GetActualVideoDim();
    InitDisplayMeasurements(size.width(), size.height(), false);
    CreatePainter();
    return result;
}
void VSimpleCopyPostprocess::InitializePostProcessor()
{
  if (m_bIsInitialized || !m_bActive)
    return;

  VASSERT_MSG(GetOwner()->IsInitialized(), "The renderer node that owns this post processor must be initialized before initializing the post processor.");

  SetupContext();

  m_bIsInitialized = true;
}
예제 #5
0
void CGSH_OpenGLAndroid::SetWindow(NativeWindowType window)
{
	m_window = window;
	m_mailBox.SendCall(
		[this] ()
		{
			SetupContext();
		},
		true
	);
}
예제 #6
0
//
//   FUNCTION: InitInstance(HINSTANCE, int)
//
//   PURPOSE: Saves instance handle and creates main window
//
//   COMMENTS:
//
//        In this function, we save the instance handle in a global variable and
//        create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;

   hInst = hInstance; // Store instance handle in our global variable

   hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, 480, 640, NULL, NULL, hInstance, NULL);

   if (!hWnd)
   {
      return FALSE;
   }

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   g_Context = SetupContext();
  


   return TRUE;
}
예제 #7
0
void CAESinkPULSE::EnumerateDevicesEx(AEDeviceInfoList &list, bool force)
{
  pa_context *context;
  pa_threaded_mainloop *mainloop;

  if (!SetupContext(NULL, &context, &mainloop))
  {
    CLog::Log(LOGNOTICE, "PulseAudio might not be running. Context was not created.");
    return;
  }

  pa_threaded_mainloop_lock(mainloop);

  SinkInfoStruct sinkStruct;
  sinkStruct.mainloop = mainloop;
  sinkStruct.list = &list;
  WaitForOperation(pa_context_get_sink_info_list(context, SinkInfoRequestCallback, &sinkStruct), mainloop, "EnumerateAudioSinks");

  pa_threaded_mainloop_unlock(mainloop);

  if (mainloop)
    pa_threaded_mainloop_stop(mainloop);

  if (context)
  {
    pa_context_disconnect(context);
    pa_context_unref(context);
    context = NULL;
  }

  if (mainloop)
  {
    pa_threaded_mainloop_free(mainloop);
    mainloop = NULL;
  }
}
예제 #8
0
 virtual FileStream::Ptr CreateStream(Binary::OutputStream::Ptr stream) const
 {
   const LameContextPtr context = LameContextPtr(LameApi->lame_init(), boost::bind(&Api::lame_close, LameApi, _1));
   SetupContext(*context);
   return boost::make_shared<FileStream>(LameApi, context, stream);
 }
예제 #9
0
 void ScriptSystem::OnAddedToEntityManager(dtEntity::EntityManager& em)
 {
    SetupContext();      
    em.AddDeletedCallback(this);
 }
예제 #10
0
bool CAESinkPULSE::Initialize(AEAudioFormat &format, std::string &device)
{
  {
    CSingleLock lock(m_sec);
    m_IsAllocated = false;
  }
  m_passthrough = false;
  m_BytesPerSecond = 0;
  m_BufferSize = 0;
  m_filled_bytes = 0;
  m_lastPackageStamp = 0;
  m_Channels = 0;
  m_Stream = NULL;
  m_Context = NULL;
  m_periodSize = 0;

  if (!SetupContext(NULL, &m_Context, &m_MainLoop))
  {
    CLog::Log(LOGNOTICE, "PulseAudio might not be running. Context was not created.");
    Deinitialize();
    return false;
  }

  pa_threaded_mainloop_lock(m_MainLoop);

  struct pa_channel_map map;
  pa_channel_map_init(&map);

   // PULSE cannot cope with e.g. planar formats so we fallback to FLOAT
   // when we receive an invalid pulse format
   if (AEFormatToPulseFormat(format.m_dataFormat) == PA_SAMPLE_INVALID)
   {
     CLog::Log(LOGDEBUG, "PULSE does not support format: %s - will fallback to AE_FMT_FLOAT", CAEUtil::DataFormatToStr(format.m_dataFormat));
     format.m_dataFormat = AE_FMT_FLOAT;
   }

  m_passthrough = AE_IS_RAW(format.m_dataFormat);

  if(m_passthrough)
  {
    map.channels = 2;
    format.m_channelLayout = AE_CH_LAYOUT_2_0;
  }
  else
  {
    map = AEChannelMapToPAChannel(format.m_channelLayout);
    // if count has changed we need to fit the AE Map
    if(map.channels != format.m_channelLayout.Count())
      format.m_channelLayout = PAChannelToAEChannelMap(map);
  }
  m_Channels = format.m_channelLayout.Count();

  // store information about current sink
  SinkInfoStruct sinkStruct;
  sinkStruct.mainloop = m_MainLoop;
  sinkStruct.device_found = false;

  // get real sample rate of the device we want to open - to avoid resampling
  bool isDefaultDevice = (device == "Default");
  WaitForOperation(pa_context_get_sink_info_by_name(m_Context, isDefaultDevice ? NULL : device.c_str(), SinkInfoCallback, &sinkStruct), m_MainLoop, "Get Sink Info");
  // only check if the device is existing - don't alter the sample rate
  if (!sinkStruct.device_found)
  {
    CLog::Log(LOGERROR, "PulseAudio: Sink %s not found", device.c_str());
    pa_threaded_mainloop_unlock(m_MainLoop);
    Deinitialize();
    return false;
  }

  // Pulse can resample everything between 1 hz and 192000 hz
  // Make sure we are in the range that we originally added
  format.m_sampleRate = std::max(5512U, std::min(format.m_sampleRate, 192000U));

  pa_format_info *info[1];
  info[0] = pa_format_info_new();
  info[0]->encoding = AEFormatToPulseEncoding(format.m_dataFormat);
  if(!m_passthrough)
  {
    pa_format_info_set_sample_format(info[0], AEFormatToPulseFormat(format.m_dataFormat));
    pa_format_info_set_channel_map(info[0], &map);
  }
  pa_format_info_set_channels(info[0], m_Channels);

  // PA requires m_encodedRate in order to do EAC3
  unsigned int samplerate = format.m_sampleRate;
  if (m_passthrough && (AEFormatToPulseEncoding(format.m_dataFormat) == PA_ENCODING_EAC3_IEC61937))
  {
    // this is only used internally for PA to use EAC3
    samplerate = format.m_encodedRate;
  }

  pa_format_info_set_rate(info[0], samplerate);

  if (!pa_format_info_valid(info[0]))
  {
    CLog::Log(LOGERROR, "PulseAudio: Invalid format info");
    pa_format_info_free(info[0]);
    pa_threaded_mainloop_unlock(m_MainLoop);
    Deinitialize();
    return false;
  }

  pa_sample_spec spec;
  #if PA_CHECK_VERSION(2,0,0)
    pa_format_info_to_sample_spec(info[0], &spec, NULL);
  #else
    spec.rate = (AEFormatToPulseEncoding(format.m_dataFormat) == PA_ENCODING_EAC3_IEC61937) ? 4 * samplerate : samplerate;
    spec.format = AEFormatToPulseFormat(format.m_dataFormat);
    spec.channels = m_Channels;
  #endif
  if (!pa_sample_spec_valid(&spec))
  {
    CLog::Log(LOGERROR, "PulseAudio: Invalid sample spec");
    pa_format_info_free(info[0]);
    pa_threaded_mainloop_unlock(m_MainLoop);
    Deinitialize();
    return false;
  }

  m_BytesPerSecond = pa_bytes_per_second(&spec);
  unsigned int frameSize = pa_frame_size(&spec);

  m_Stream = pa_stream_new_extended(m_Context, "kodi audio stream", info, 1, NULL);
  pa_format_info_free(info[0]);

  if (m_Stream == NULL)
  {
    CLog::Log(LOGERROR, "PulseAudio: Could not create a stream");
    pa_threaded_mainloop_unlock(m_MainLoop);
    Deinitialize();
    return false;
  }

  pa_stream_set_state_callback(m_Stream, StreamStateCallback, m_MainLoop);
  pa_stream_set_write_callback(m_Stream, StreamRequestCallback, m_MainLoop);
  pa_stream_set_latency_update_callback(m_Stream, StreamLatencyUpdateCallback, m_MainLoop);

  // default buffer construction
  // align with AE's max buffer
  unsigned int latency = m_BytesPerSecond / 2.5; // 400 ms
  unsigned int process_time = latency / 4; // 100 ms
  if(sinkStruct.isHWDevice)
  {
    // on hw devices buffers can be further reduced
    // 200ms max latency
    // 50ms min packet size
    latency = m_BytesPerSecond / 5;
    process_time = latency / 4;
  }

  pa_buffer_attr buffer_attr;
  buffer_attr.fragsize = latency;
  buffer_attr.maxlength = (uint32_t) -1;
  buffer_attr.minreq = process_time;
  buffer_attr.prebuf = (uint32_t) -1;
  buffer_attr.tlength = latency;

  if (pa_stream_connect_playback(m_Stream, isDefaultDevice ? NULL : device.c_str(), &buffer_attr, ((pa_stream_flags)(PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_AUTO_TIMING_UPDATE | PA_STREAM_ADJUST_LATENCY)), NULL, NULL) < 0)
  {
    CLog::Log(LOGERROR, "PulseAudio: Failed to connect stream to output");
    pa_threaded_mainloop_unlock(m_MainLoop);
    Deinitialize();
    return false;
  }

  /* Wait until the stream is ready */
  do
  {
    pa_threaded_mainloop_wait(m_MainLoop);
    CLog::Log(LOGDEBUG, "PulseAudio: Stream %s", StreamStateToString(pa_stream_get_state(m_Stream)));
  }
  while (pa_stream_get_state(m_Stream) != PA_STREAM_READY && pa_stream_get_state(m_Stream) != PA_STREAM_FAILED);

  if (pa_stream_get_state(m_Stream) == PA_STREAM_FAILED)
  {
    CLog::Log(LOGERROR, "PulseAudio: Waited for the stream but it failed");
    pa_threaded_mainloop_unlock(m_MainLoop);
    Deinitialize();
    return false;
  }

  const pa_buffer_attr *a;

  if (!(a = pa_stream_get_buffer_attr(m_Stream)))
  {
    CLog::Log(LOGERROR, "PulseAudio: %s", pa_strerror(pa_context_errno(m_Context)));
    pa_threaded_mainloop_unlock(m_MainLoop);
    Deinitialize();
    return false;
  }
  else
  {
    unsigned int packetSize = a->minreq;
    m_BufferSize = a->tlength;
    m_periodSize = a->minreq;

    format.m_frames = packetSize / frameSize;
  }

  {
    CSingleLock lock(m_sec);
    // Register Callback for Sink changes
    pa_context_set_subscribe_callback(m_Context, SinkChangedCallback, this);
    const pa_subscription_mask_t mask = PA_SUBSCRIPTION_MASK_SINK;
    pa_operation *op = pa_context_subscribe(m_Context, mask, NULL, this);
    if (op != NULL)
      pa_operation_unref(op);

    // Register Callback for Sink Info changes - this handles volume
    pa_context_set_subscribe_callback(m_Context, SinkInputInfoChangedCallback, this);
    const pa_subscription_mask_t mask_input = PA_SUBSCRIPTION_MASK_SINK_INPUT;
    pa_operation* op_sinfo = pa_context_subscribe(m_Context, mask_input, NULL, this);
    if (op_sinfo != NULL)
      pa_operation_unref(op_sinfo);
  }

  pa_threaded_mainloop_unlock(m_MainLoop);
  
  format.m_frameSize = frameSize;
  format.m_frameSamples = format.m_frames * format.m_channelLayout.Count();
  m_format = format;
  format.m_dataFormat = m_passthrough ? AE_FMT_S16NE : format.m_dataFormat;

  CLog::Log(LOGNOTICE, "PulseAudio: Opened device %s in %s mode with Buffersize %u ms",
                      device.c_str(), m_passthrough ? "passthrough" : "pcm",
                      (unsigned int) ((m_BufferSize / (float) m_BytesPerSecond) * 1000));

  // Cork stream will resume when adding first package
  Pause(true);
  {
    CSingleLock lock(m_sec);
    m_IsAllocated = true;
  }

  return true;
}
예제 #11
0
void VPostProcessFXAA::InitializePostProcessor()
{
  if (m_bIsInitialized || !m_bActive)
    return;

  SetupContext();

  // Load glow shader library
  BOOL bResult = Vision::Shaders.LoadShaderLibrary("\\Shaders\\FXAA.ShaderLib", SHADERLIBFLAG_HIDDEN) != NULL;
  VASSERT(bResult); // file not found?

  GetTargetContext()->GetSize(m_iWidth, m_iHeight);

  m_spMask = new VisScreenMask_cl();
  m_spMask->SetPos(0,0);
  m_spMask->SetTargetSize((float)m_iWidth,(float)m_iHeight);
  m_spMask->SetTextureRange(0.0f, 0.0f, (float)m_iWidth, (float)m_iHeight);
#ifdef _VR_DX9
  m_spMask->SetUseOpenGLTexelShift(TRUE);
#else
  m_spMask->SetUseOpenGLTexelShift(FALSE);
#endif
  //m_spMask->SetUseOpenGLTexelShift(FALSE);

  m_spMask->SetTransparency(VIS_TRANSP_NONE);
  m_spMask->SetVisible(FALSE);
  m_spMask->SetDepthWrite(FALSE);
  m_spMask->SetWrapping(FALSE, FALSE);
  m_spMask->SetVisibleBitmask(0); // this mask is rendered manually via a collection

  // no wireframe for this mask
  VSimpleRenderState_t s = m_spMask->GetRenderState();
  s.SetFlag(RENDERSTATEFLAG_NOWIREFRAME);
  m_spMask->SetRenderState(s);

  VTechniqueConfig vc;

  VString tags;
  tags.Format("FXAA_PRESET=%d", (int)Quality);
  vc.SetInclusionTags(tags);

  VCompiledTechnique *pTech = Vision::Shaders.CreateTechnique("FXAA", NULL, &vc, EFFECTFLAGS_FORCEUNIQUE);
  VASSERT(pTech!=NULL && "Could not create technique for FXAA postprocessor!");
  m_spMask->SetTechnique(pTech);
  m_spMask->SetTransparency(VIS_TRANSP_NONE);

  VShaderConstantBuffer *pPS = pTech->GetShader(0)->GetConstantBuffer(VSS_PixelShader);
  m_iRegScreenSize = pPS->GetRegisterByName("rcpFrame");
  
  // make frame copy only if this is not the last PP
  bool bFrameCopy = !IsLastComponent();
  if (bFrameCopy && GetTargetContext()->GetRenderTarget() == m_spSourceTextures[0])
  {
    m_spFrameCopyTexture = ScratchTexturePool_cl::GlobalManager().GetScratchTexture(m_iWidth, m_iHeight, m_spSourceTextures[0]->GetTextureFormat(), 0);
    m_spMask->SetTextureObject(m_spFrameCopyTexture);
  }
  else
  {
    m_spFrameCopyTexture = NULL;
    m_spMask->SetTextureObject(m_spSourceTextures[0]);
  }

  m_bIsInitialized = true;
}
예제 #12
0
파일: win32.c 프로젝트: HintonBR/scratch
LRESULT CALLBACK
WinProc(HWND   hWnd,   /* I - Window triggering this event */
        UINT   uMsg,   /* I - Message type */
        WPARAM wParam, /* I - 'word' parameter value */
        LPARAM lParam) /* I - 'long' parameter value */
    {
    PAINTSTRUCT ps;    /* WM_PAINT message info */
    RECT        rect;  /* Current client area rectangle */


    switch (uMsg)
        {
        case WM_CREATE :
            /*
             * 'Create' message.  Get device and rendering contexts, and 
	     * setup the client area for OpenGL drawing...
	     */

            DC = GetDC(hWnd);
	    SetupContext();
	    break;

        case WM_SIZE :
            /*
	     * Handle resizes...
	     */

            GetClientRect(hWnd, &rect);
	    Resize(rect.right, rect.bottom);

        case WM_PAINT :
            /*
             * Repaint the client area...
	     */

            BeginPaint(hWnd, &ps);
	    Redraw();
	    EndPaint(hWnd, &ps);
	    break;

        case WM_QUIT :
        case WM_CLOSE :
            /*
             * Destroy the window and exit...
             */

            DestroyWindow(Window);
            exit(0);
            break;

        case WM_DESTROY :
            /*
             * Release and free the device context, rendering
             * context, and color palette...
	     */

            if (RC)
    	        wglDeleteContext(RC);

            if (DC)
    	        ReleaseDC(Window, DC);

	    if (Palette)
	        DeleteObject(Palette);

            PostQuitMessage(0);
            break;

        case WM_QUERYNEWPALETTE :
            /*
             * Realize the color palette if necessary...
	     */

            if (Palette)
	        {
                SelectPalette(DC, Palette, FALSE);
                RealizePalette(DC);

                InvalidateRect(hWnd, NULL, FALSE);
	        return (TRUE);
	        }
            break;

        case WM_PALETTECHANGED:
            /*
             * Reselect our color palette if necessary...
	     */

            if (Palette && (HWND)wParam != hWnd)
	        {
                SelectPalette(DC, Palette, FALSE);
                RealizePalette(DC);

                UpdateColors(DC);
	        }
	    break;

        case WM_CHAR :
	    /*
	     * Handle key presses...
	     */

	    Keyboard((unsigned char)wParam, 0, 0);
	    break;

        default :
            /*
             * Pass all other messages through the default window
             * procedure...
             */

            return (DefWindowProc(hWnd, uMsg, wParam, lParam));
        }

    return (FALSE);
    }
예제 #13
0
 FileStream::Ptr CreateStream(Binary::OutputStream::Ptr stream) const override
 {
   const LameContextPtr context = LameContextPtr(LameApi->lame_init(), boost::bind(&Api::lame_close, LameApi, _1));
   SetupContext(*context);
   return MakePtr<FileStream>(LameApi, context, stream);
 }