Beispiel #1
0
int MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx)
{
    int i;
    AVFrame *pic;
    s->mb_skiped = 0;

    if (s->pict_type != B_TYPE && s->last_picture_ptr && s->last_picture_ptr->data[0])
	{
        avcodec_default_release_buffer(avctx, (AVFrame*)s->last_picture_ptr);
    
        for(i=0; i<MAX_PICTURE_COUNT; i++)
		{
            if(s->picture[i].data[0] && &s->picture[i] != s->next_picture_ptr && s->picture[i].reference)
			{
                avcodec_default_release_buffer(avctx, (AVFrame*)&s->picture[i]);
            }
        }
    }

    for(i=0; i<MAX_PICTURE_COUNT; i++)
	{
        if(s->picture[i].data[0] && !s->picture[i].reference /*&& s->picture[i].type!=FF_BUFFER_TYPE_SHARED*/)
		{
            avcodec_default_release_buffer(s->avctx, (AVFrame*)&s->picture[i]);
        }
    }

    if(s->current_picture_ptr && s->current_picture_ptr->data[0]==NULL)
        pic= (AVFrame*)s->current_picture_ptr; //we allready have a unused image (maybe it was set before reading the header)
    else
	{
        i= ff_find_unused_picture(s, 0);
        pic= (AVFrame*)&s->picture[i];
    }

    pic->reference= s->pict_type != B_TYPE ? 3 : 0;

    if( alloc_picture(s, (Picture*)pic, 0) < 0)
        return -1;

    s->current_picture_ptr= (Picture*)pic;

    s->current_picture_ptr->pict_type= s->pict_type;
    s->current_picture_ptr->key_frame= s->pict_type == I_TYPE;

    copy_picture(&s->current_picture, s->current_picture_ptr);

    s->hurry_up= s->avctx->hurry_up;

    return 0;
}
// Called by the DecoderMF class when we have a new frame.
// We convert and copy the frame into BGRA32 format and place
// into the m_textureBuffer buffer.
//
// Thread context: decoder thread
bool PreviewWindow::DrawFrame(IMFMediaBuffer* mediaBuffer)
{
	bool			ret = false;
	HRESULT			hr;
	BYTE*			pData = NULL;
	BYTE*			pScanLine0;

	if (m_hwnd == NULL)
		return true;

	hr = m_device->TestCooperativeLevel();
    if(hr == D3DERR_DEVICELOST)
        return false;
    else if(hr == D3DERR_DEVICENOTRESET || m_needsReset)
        if(!reset())
            return false;

	EnterCriticalSection(&m_criticalSection);

		// Get the pointer to the data
		hr = mediaBuffer->Lock(&pData, NULL, NULL);
		if (FAILED(hr))
			goto bail;

		if (m_defaultStride < 0)
			pScanLine0 = pData + abs((long)m_defaultStride) * (m_height - 1);
		else
			pScanLine0 = pData;

		if(!m_surface)
		{
			hr = m_device->CreateOffscreenPlainSurface(m_width, m_height, D3DFMT_YUY2, D3DPOOL_DEFAULT, &m_surface, NULL);
			ATLASSERT(hr == S_OK);
		}
		D3DLOCKED_RECT locked;
		RECT rc;
		rc.left = 0;
		rc.top = 0;
		rc.right = m_width;
		rc.bottom = m_height;
		if(m_surface->LockRect(&locked, &rc, D3DLOCK_DISCARD) == S_OK)
		{
			copy_picture(pScanLine0, (BYTE*)locked.pBits, m_width*2, m_width*2, locked.Pitch, m_height);
			m_surface->UnlockRect();
		}

		hr = mediaBuffer->Unlock();
		if (FAILED(hr))
			goto bail;

		{
			CComPtr<IDirect3DSurface9> screen_surface;
			m_device->GetRenderTarget(0, &screen_surface);
			m_device->StretchRect(m_surface, &rc, screen_surface, NULL, D3DTEXF_LINEAR);
		}

		if (m_newTextureInBuffer)
			OutputDebugString(_T("WARNING: overwriten undisplayed texture\n"));
		m_newTextureInBuffer = true;

	ret = true;

bail:
	LeaveCriticalSection(&m_criticalSection);

	if (ret)
		InvalidateRect(m_hwnd, NULL, FALSE);
	return ret;
}