기존 파일의 ASF 헤더 개체 읽기

ASF ContentInfo 개체는 미디어 파일의 ASF 헤더 개체를 나타내는 정보를 저장합니다. 기존 ASF 파일을 읽고 구문 분석하려면 채워진 ContentInfo 개체가 필요합니다.

MFCreateASFContentInfo 함수를 호출하여 ContentInfo 개체를 만든 후 애플리케이션은 읽을 ASF 파일의 헤더 정보로 초기화해야 합니다. 개체를 채우려면 IMFASFContentInfo::P arseHeader를 호출합니다.

ParseHeader 에는 ASF 파일의 헤더 개체를 포함하는 미디어 버퍼가 필요합니다. 한 가지 옵션은 미디어 버퍼를 헤더 개체로 채워 파일에 대한 바이트 스트림을 만든 다음 바이트 스트림에서 미디어 버퍼로 처음 30바이트의 데이터를 읽는 것입니다. 그런 다음 헤더 개체의 처음 24바이트를 IMFASFContentInfo::GetHeaderSize 메서드에 전달하여 크기를 가져올 수 있습니다. 크기를 얻은 후 미디어 버퍼에서 전체 Header 개체를 읽고 ParseHeader에 전달할 수 있습니다. 메서드는 cbOffsetWithinHeader 매개 변수에 지정된 미디어 버퍼의 시작부터 오프셋에서 구문 분석을 시작합니다.

다음 예제 코드는 바이트 스트림에 포함된 기존 ASF 파일을 읽기 위해 ContentInfo 개체를 만들고 초기화합니다. 먼저 바이트 스트림에서 데이터를 읽고 데이터를 저장할 미디어 버퍼를 할당하는 도우미 함수를 정의합니다.

// Read the ASF Header Object from a byte stream and return a pointer to the 
// populated ASF ContentInfo object.
//
// The current read position of the byte stream must be at the start of the
// ASF Header Object.

HRESULT CreateContentInfo(IMFByteStream *pStream, 
    IMFASFContentInfo **ppContentInfo)
{
    const DWORD MIN_ASF_HEADER_SIZE = 30;
    
    QWORD cbHeader = 0;
    DWORD cbBuffer = 0;

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

    // Create the ASF ContentInfo object.
    HRESULT hr = MFCreateASFContentInfo(&pContentInfo);
    
    // Read the first 30 bytes to find the total header size.

    if (SUCCEEDED(hr))
    {
        hr = MFCreateMemoryBuffer(MIN_ASF_HEADER_SIZE, &pBuffer);
    }
    if (SUCCEEDED(hr))
    {
        hr = ReadFromByteStream(pStream, pBuffer,MIN_ASF_HEADER_SIZE);
    }
    if (SUCCEEDED(hr))
    {
        hr = pContentInfo->GetHeaderSize(pBuffer, &cbHeader);
    }

    // Pass the first 30 bytes to the ContentInfo object.
    if (SUCCEEDED(hr))
    {
        hr = pContentInfo->ParseHeader(pBuffer, 0);
    }

    SafeRelease(&pBuffer);

    if (SUCCEEDED(hr))
    {
        cbBuffer = (DWORD)(cbHeader - MIN_ASF_HEADER_SIZE);

        hr = MFCreateMemoryBuffer(cbBuffer, &pBuffer);
    }

    // Read the rest of the header and finish parsing the header.
    if (SUCCEEDED(hr))
    {
        hr = ReadFromByteStream(pStream, pBuffer, cbBuffer);
    }
    if (SUCCEEDED(hr))
    {
        hr = pContentInfo->ParseHeader(pBuffer, MIN_ASF_HEADER_SIZE);
    }
    if (SUCCEEDED(hr))
    {
        // Return the pointer to the caller.
        *ppContentInfo = pContentInfo;
        (*ppContentInfo)->AddRef();
    }
    SafeRelease(&pBuffer);
    SafeRelease(&pContentInfo);
    return hr;
} 

다음 예제에서는 바이트 스트림에서 ASF Header 개체를 읽고 ASF ContentInfo 개체를 채웁니다.

// Read the ASF Header Object from a byte stream and return a pointer to the 
// populated ASF ContentInfo object.
//
// The current read position of the byte stream must be at the start of the
// ASF Header Object.

HRESULT CreateContentInfo(IMFByteStream *pStream, 
    IMFASFContentInfo **ppContentInfo)
{
    const DWORD MIN_ASF_HEADER_SIZE = 30;
    
    QWORD cbHeader = 0;
    DWORD cbBuffer = 0;

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

    // Create the ASF ContentInfo object.
    HRESULT hr = MFCreateASFContentInfo(&pContentInfo);
    
    // Read the first 30 bytes to find the total header size.

    if (SUCCEEDED(hr))
    {
        hr = MFCreateMemoryBuffer(MIN_ASF_HEADER_SIZE, &pBuffer);
    }
    if (SUCCEEDED(hr))
    {
        hr = ReadFromByteStream(pStream, pBuffer,MIN_ASF_HEADER_SIZE);
    }
    if (SUCCEEDED(hr))
    {
        hr = pContentInfo->GetHeaderSize(pBuffer, &cbHeader);
    }

    // Pass the first 30 bytes to the ContentInfo object.
    if (SUCCEEDED(hr))
    {
        hr = pContentInfo->ParseHeader(pBuffer, 0);
    }

    SafeRelease(&pBuffer);

    if (SUCCEEDED(hr))
    {
        cbBuffer = (DWORD)(cbHeader - MIN_ASF_HEADER_SIZE);

        hr = MFCreateMemoryBuffer(cbBuffer, &pBuffer);
    }

    // Read the rest of the header and finish parsing the header.
    if (SUCCEEDED(hr))
    {
        hr = ReadFromByteStream(pStream, pBuffer, cbBuffer);
    }
    if (SUCCEEDED(hr))
    {
        hr = pContentInfo->ParseHeader(pBuffer, MIN_ASF_HEADER_SIZE);
    }
    if (SUCCEEDED(hr))
    {
        // Return the pointer to the caller.
        *ppContentInfo = pContentInfo;
        (*ppContentInfo)->AddRef();
    }
    SafeRelease(&pBuffer);
    SafeRelease(&pContentInfo);
    return hr;
} 

참고

이러한 예제에서는 SafeRelease 함수를 사용하여 인터페이스 포인터를 해제합니다.

 

ASF ContentInfo 개체

ASF 헤더 개체

Media Foundation의 ASF 지원

ASF 헤더 개체에서 정보 가져오기