Пример #1
0
AsfContentInfoBuilder::AsfContentInfoBuilder()
{
  IPropertyStore* fileLevelEncodingConfiguration = nullptr;
  HRESULT hr;

  _mfAsfContentInfo = nullptr;
  _mfAsfProfile = nullptr;
  _mfMetadataProvider = nullptr;
  _mfMetadata = nullptr;

  do
  {
    if (!SUCCEEDED(hr = MFCreateASFContentInfo(&_mfAsfContentInfo)))
      break;

    if (!SUCCEEDED(hr = MFCreateASFProfile(&_mfAsfProfile)))
      break;

    if (!SUCCEEDED(hr = _mfAsfContentInfo->QueryInterface(IID_IMFMetadataProvider, (void**)&_mfMetadataProvider)))
      break;

    if (!SUCCEEDED(hr = _mfMetadataProvider->GetMFMetadata(NULL, 0, 0, &_mfMetadata)))
      break;

    // Set MFPKEY_ASFMEDIASINK_AUTOADJUST_BITRATE to true on the file-level encoding configuration
    // property store.  Does this actually do anything?  Is it needed?

    if (!SUCCEEDED(hr = _mfAsfContentInfo->GetEncodingConfigurationPropertyStore(0, &fileLevelEncodingConfiguration)))
      break;

    PROPVARIANT pv;
    InitPropVariantFromBoolean(TRUE, &pv);

    if (!SUCCEEDED(hr = fileLevelEncodingConfiguration->SetValue(MFPKEY_ASFMEDIASINK_AUTOADJUST_BITRATE, pv)))
      break;

    PropVariantClear(&pv);

  } while (0);

  if (fileLevelEncodingConfiguration) fileLevelEncodingConfiguration->Release();

  if (FAILED(hr))
  {
    if (_mfMetadata) _mfMetadata->Release();
    if (_mfMetadataProvider) _mfMetadataProvider->Release();
    if (_mfAsfProfile) _mfAsfProfile->Release();
    if (_mfAsfContentInfo) _mfAsfContentInfo->Release();

    throw std::exception("Unable to create MediaSinkContentInfo object");
  }
}
HRESULT CASFManager::CreateASFContentInfo (IMFByteStream *pContentByteStream,
                                           IMFASFContentInfo **ppContentInfo)
{
    if (!pContentByteStream || !ppContentInfo)
    {
        return E_INVALIDARG;
    }
 
    HRESULT hr = S_OK;
    QWORD cbHeader = 0;

   
    IMFASFContentInfo *pContentInfo = NULL;
    IMFMediaBuffer *pBuffer = NULL;

    // Create the ASF content information object.
    CHECK_HR(hr = MFCreateASFContentInfo(&pContentInfo));
    
    // Read the first 30 bytes to find the total header size.
    CHECK_HR(hr = ReadDataIntoBuffer(
        pContentByteStream, 0, MIN_ASF_HEADER_SIZE, &pBuffer));

    CHECK_HR(hr = pContentInfo->GetHeaderSize(pBuffer, &cbHeader));

    SAFE_RELEASE(pBuffer);
    
    //Read the header into a buffer
    CHECK_HR(hr = ReadDataIntoBuffer(
        pContentByteStream, 0, (DWORD)cbHeader, &pBuffer));

    // Pass the buffer for the header object.
    CHECK_HR(hr = pContentInfo->ParseHeader(pBuffer, 0));


    // Return the pointer to the caller.
    *ppContentInfo = pContentInfo;
    (*ppContentInfo)->AddRef();

    TRACE((L"Created ContentInfo object.\n"));

done:
    
    LOG_MSG_IF_FAILED(L"CASFManager::CreateASFContentInfo failed.\n", hr);

    SAFE_RELEASE(pBuffer);
    SAFE_RELEASE(pContentInfo);
    return hr;
}