Win32 API 日本語リファレンス
ホームMedia.MediaFoundation › MFCreateSourceReaderFromByteStream

MFCreateSourceReaderFromByteStream

関数
バイトストリームからメディアソースリーダーを作成する。
DLLMFReadWrite.dll呼出規約winapi対応OSWindows 7 以降

シグネチャ

// MFReadWrite.dll
#include <windows.h>

HRESULT MFCreateSourceReaderFromByteStream(
    IMFByteStream* pByteStream,
    IMFAttributes* pAttributes,   // optional
    IMFSourceReader** ppSourceReader
);

パラメーター

名前方向説明
pByteStreamIMFByteStream*inバイトストリームの IMFByteStream インターフェイスへのポインターです。このバイトストリームは、ソースリーダーにソースデータを提供します。
pAttributesIMFAttributes*inoptionalIMFAttributes インターフェイスへのポインターです。このパラメーターを使用してソースリーダーを構成できます。詳細については、Source Reader Attributes を参照してください。このパラメーターは NULL にできます。
ppSourceReaderIMFSourceReader**outIMFSourceReader インターフェイスへのポインターを受け取ります。呼び出し元はこのインターフェイスを解放する必要があります。

戻り値の型: HRESULT

公式ドキュメント

バイトストリームからソースリーダーを作成します。

戻り値

この関数が成功した場合は S_OK を返します。それ以外の場合は HRESULT エラーコードを返します。

解説(Remarks)

この関数を呼び出す前に、CoInitialize(Ex)MFStartup を呼び出してください。

内部的に、ソースリーダーは IMFSourceResolver::CreateObjectFromByteStream メソッドを呼び出して、バイトストリームからメディアソースを作成します。そのため、対象のバイトストリーム用にバイトストリームハンドラーが登録されている必要があります。バイトストリームハンドラーの詳細については、Scheme Handlers and Byte-Stream Handlers を参照してください。

この関数は、Platform Update Supplement for Windows Vista がインストールされている場合に Windows Vista で使用できます。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// MFReadWrite.dll
#include <windows.h>

HRESULT MFCreateSourceReaderFromByteStream(
    IMFByteStream* pByteStream,
    IMFAttributes* pAttributes,   // optional
    IMFSourceReader** ppSourceReader
);
[DllImport("MFReadWrite.dll", ExactSpelling = true)]
static extern int MFCreateSourceReaderFromByteStream(
    IntPtr pByteStream,   // IMFByteStream*
    IntPtr pAttributes,   // IMFAttributes* optional
    IntPtr ppSourceReader   // IMFSourceReader** out
);
<DllImport("MFReadWrite.dll", ExactSpelling:=True)>
Public Shared Function MFCreateSourceReaderFromByteStream(
    pByteStream As IntPtr,   ' IMFByteStream*
    pAttributes As IntPtr,   ' IMFAttributes* optional
    ppSourceReader As IntPtr   ' IMFSourceReader** out
) As Integer
End Function
' pByteStream : IMFByteStream*
' pAttributes : IMFAttributes* optional
' ppSourceReader : IMFSourceReader** out
Declare PtrSafe Function MFCreateSourceReaderFromByteStream Lib "mfreadwrite" ( _
    ByVal pByteStream As LongPtr, _
    ByVal pAttributes As LongPtr, _
    ByVal ppSourceReader As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

MFCreateSourceReaderFromByteStream = ctypes.windll.mfreadwrite.MFCreateSourceReaderFromByteStream
MFCreateSourceReaderFromByteStream.restype = ctypes.c_int
MFCreateSourceReaderFromByteStream.argtypes = [
    ctypes.c_void_p,  # pByteStream : IMFByteStream*
    ctypes.c_void_p,  # pAttributes : IMFAttributes* optional
    ctypes.c_void_p,  # ppSourceReader : IMFSourceReader** out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('MFReadWrite.dll')
MFCreateSourceReaderFromByteStream = Fiddle::Function.new(
  lib['MFCreateSourceReaderFromByteStream'],
  [
    Fiddle::TYPE_VOIDP,  # pByteStream : IMFByteStream*
    Fiddle::TYPE_VOIDP,  # pAttributes : IMFAttributes* optional
    Fiddle::TYPE_VOIDP,  # ppSourceReader : IMFSourceReader** out
  ],
  Fiddle::TYPE_INT)
#[link(name = "mfreadwrite")]
extern "system" {
    fn MFCreateSourceReaderFromByteStream(
        pByteStream: *mut core::ffi::c_void,  // IMFByteStream*
        pAttributes: *mut core::ffi::c_void,  // IMFAttributes* optional
        ppSourceReader: *mut *mut core::ffi::c_void  // IMFSourceReader** out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("MFReadWrite.dll")]
public static extern int MFCreateSourceReaderFromByteStream(IntPtr pByteStream, IntPtr pAttributes, IntPtr ppSourceReader);
"@
$api = Add-Type -MemberDefinition $sig -Name 'MFReadWrite_MFCreateSourceReaderFromByteStream' -Namespace Win32 -PassThru
# $api::MFCreateSourceReaderFromByteStream(pByteStream, pAttributes, ppSourceReader)
#uselib "MFReadWrite.dll"
#func global MFCreateSourceReaderFromByteStream "MFCreateSourceReaderFromByteStream" sptr, sptr, sptr
; MFCreateSourceReaderFromByteStream pByteStream, pAttributes, ppSourceReader   ; 戻り値は stat
; pByteStream : IMFByteStream* -> "sptr"
; pAttributes : IMFAttributes* optional -> "sptr"
; ppSourceReader : IMFSourceReader** out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "MFReadWrite.dll"
#cfunc global MFCreateSourceReaderFromByteStream "MFCreateSourceReaderFromByteStream" sptr, sptr, sptr
; res = MFCreateSourceReaderFromByteStream(pByteStream, pAttributes, ppSourceReader)
; pByteStream : IMFByteStream* -> "sptr"
; pAttributes : IMFAttributes* optional -> "sptr"
; ppSourceReader : IMFSourceReader** out -> "sptr"
; HRESULT MFCreateSourceReaderFromByteStream(IMFByteStream* pByteStream, IMFAttributes* pAttributes, IMFSourceReader** ppSourceReader)
#uselib "MFReadWrite.dll"
#cfunc global MFCreateSourceReaderFromByteStream "MFCreateSourceReaderFromByteStream" intptr, intptr, intptr
; res = MFCreateSourceReaderFromByteStream(pByteStream, pAttributes, ppSourceReader)
; pByteStream : IMFByteStream* -> "intptr"
; pAttributes : IMFAttributes* optional -> "intptr"
; ppSourceReader : IMFSourceReader** out -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	mfreadwrite = windows.NewLazySystemDLL("MFReadWrite.dll")
	procMFCreateSourceReaderFromByteStream = mfreadwrite.NewProc("MFCreateSourceReaderFromByteStream")
)

// pByteStream (IMFByteStream*), pAttributes (IMFAttributes* optional), ppSourceReader (IMFSourceReader** out)
r1, _, err := procMFCreateSourceReaderFromByteStream.Call(
	uintptr(pByteStream),
	uintptr(pAttributes),
	uintptr(ppSourceReader),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function MFCreateSourceReaderFromByteStream(
  pByteStream: Pointer;   // IMFByteStream*
  pAttributes: Pointer;   // IMFAttributes* optional
  ppSourceReader: Pointer   // IMFSourceReader** out
): Integer; stdcall;
  external 'MFReadWrite.dll' name 'MFCreateSourceReaderFromByteStream';
result := DllCall("MFReadWrite\MFCreateSourceReaderFromByteStream"
    , "Ptr", pByteStream   ; IMFByteStream*
    , "Ptr", pAttributes   ; IMFAttributes* optional
    , "Ptr", ppSourceReader   ; IMFSourceReader** out
    , "Int")   ; return: HRESULT
●MFCreateSourceReaderFromByteStream(pByteStream, pAttributes, ppSourceReader) = DLL("MFReadWrite.dll", "int MFCreateSourceReaderFromByteStream(void*, void*, void*)")
# 呼び出し: MFCreateSourceReaderFromByteStream(pByteStream, pAttributes, ppSourceReader)
# pByteStream : IMFByteStream* -> "void*"
# pAttributes : IMFAttributes* optional -> "void*"
# ppSourceReader : IMFSourceReader** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "mfreadwrite" fn MFCreateSourceReaderFromByteStream(
    pByteStream: ?*anyopaque, // IMFByteStream*
    pAttributes: ?*anyopaque, // IMFAttributes* optional
    ppSourceReader: ?*anyopaque // IMFSourceReader** out
) callconv(std.os.windows.WINAPI) i32;
proc MFCreateSourceReaderFromByteStream(
    pByteStream: pointer,  # IMFByteStream*
    pAttributes: pointer,  # IMFAttributes* optional
    ppSourceReader: pointer  # IMFSourceReader** out
): int32 {.importc: "MFCreateSourceReaderFromByteStream", stdcall, dynlib: "MFReadWrite.dll".}
pragma(lib, "mfreadwrite");
extern(Windows)
int MFCreateSourceReaderFromByteStream(
    void* pByteStream,   // IMFByteStream*
    void* pAttributes,   // IMFAttributes* optional
    void* ppSourceReader   // IMFSourceReader** out
);
ccall((:MFCreateSourceReaderFromByteStream, "MFReadWrite.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}),
      pByteStream, pAttributes, ppSourceReader)
# pByteStream : IMFByteStream* -> Ptr{Cvoid}
# pAttributes : IMFAttributes* optional -> Ptr{Cvoid}
# ppSourceReader : IMFSourceReader** out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t MFCreateSourceReaderFromByteStream(
    void* pByteStream,
    void* pAttributes,
    void* ppSourceReader);
]]
local mfreadwrite = ffi.load("mfreadwrite")
-- mfreadwrite.MFCreateSourceReaderFromByteStream(pByteStream, pAttributes, ppSourceReader)
-- pByteStream : IMFByteStream*
-- pAttributes : IMFAttributes* optional
-- ppSourceReader : IMFSourceReader** out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('MFReadWrite.dll');
const MFCreateSourceReaderFromByteStream = lib.func('__stdcall', 'MFCreateSourceReaderFromByteStream', 'int32_t', ['void *', 'void *', 'void *']);
// MFCreateSourceReaderFromByteStream(pByteStream, pAttributes, ppSourceReader)
// pByteStream : IMFByteStream* -> 'void *'
// pAttributes : IMFAttributes* optional -> 'void *'
// ppSourceReader : IMFSourceReader** out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("MFReadWrite.dll", {
  MFCreateSourceReaderFromByteStream: { parameters: ["pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.MFCreateSourceReaderFromByteStream(pByteStream, pAttributes, ppSourceReader)
// pByteStream : IMFByteStream* -> "pointer"
// pAttributes : IMFAttributes* optional -> "pointer"
// ppSourceReader : IMFSourceReader** out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t MFCreateSourceReaderFromByteStream(
    void* pByteStream,
    void* pAttributes,
    void* ppSourceReader);
C, "MFReadWrite.dll");
// $ffi->MFCreateSourceReaderFromByteStream(pByteStream, pAttributes, ppSourceReader);
// pByteStream : IMFByteStream*
// pAttributes : IMFAttributes* optional
// ppSourceReader : IMFSourceReader** out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Mfreadwrite extends StdCallLibrary {
    Mfreadwrite INSTANCE = Native.load("mfreadwrite", Mfreadwrite.class);
    int MFCreateSourceReaderFromByteStream(
        Pointer pByteStream,   // IMFByteStream*
        Pointer pAttributes,   // IMFAttributes* optional
        Pointer ppSourceReader   // IMFSourceReader** out
    );
}
@[Link("mfreadwrite")]
lib LibMFReadWrite
  fun MFCreateSourceReaderFromByteStream = MFCreateSourceReaderFromByteStream(
    pByteStream : Void*,   # IMFByteStream*
    pAttributes : Void*,   # IMFAttributes* optional
    ppSourceReader : Void*   # IMFSourceReader** out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef MFCreateSourceReaderFromByteStreamNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Void>);
typedef MFCreateSourceReaderFromByteStreamDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Void>);
final MFCreateSourceReaderFromByteStream = DynamicLibrary.open('MFReadWrite.dll')
    .lookupFunction<MFCreateSourceReaderFromByteStreamNative, MFCreateSourceReaderFromByteStreamDart>('MFCreateSourceReaderFromByteStream');
// pByteStream : IMFByteStream* -> Pointer<Void>
// pAttributes : IMFAttributes* optional -> Pointer<Void>
// ppSourceReader : IMFSourceReader** out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function MFCreateSourceReaderFromByteStream(
  pByteStream: Pointer;   // IMFByteStream*
  pAttributes: Pointer;   // IMFAttributes* optional
  ppSourceReader: Pointer   // IMFSourceReader** out
): Integer; stdcall;
  external 'MFReadWrite.dll' name 'MFCreateSourceReaderFromByteStream';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "MFCreateSourceReaderFromByteStream"
  c_MFCreateSourceReaderFromByteStream :: Ptr () -> Ptr () -> Ptr () -> IO Int32
-- pByteStream : IMFByteStream* -> Ptr ()
-- pAttributes : IMFAttributes* optional -> Ptr ()
-- ppSourceReader : IMFSourceReader** out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let mfcreatesourcereaderfrombytestream =
  foreign "MFCreateSourceReaderFromByteStream"
    ((ptr void) @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* pByteStream : IMFByteStream* -> (ptr void) *)
(* pAttributes : IMFAttributes* optional -> (ptr void) *)
(* ppSourceReader : IMFSourceReader** out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library mfreadwrite (t "MFReadWrite.dll"))
(cffi:use-foreign-library mfreadwrite)

(cffi:defcfun ("MFCreateSourceReaderFromByteStream" mfcreate-source-reader-from-byte-stream :convention :stdcall) :int32
  (p-byte-stream :pointer)   ; IMFByteStream*
  (p-attributes :pointer)   ; IMFAttributes* optional
  (pp-source-reader :pointer))   ; IMFSourceReader** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $MFCreateSourceReaderFromByteStream = Win32::API::More->new('MFReadWrite',
    'int MFCreateSourceReaderFromByteStream(LPVOID pByteStream, LPVOID pAttributes, LPVOID ppSourceReader)');
# my $ret = $MFCreateSourceReaderFromByteStream->Call($pByteStream, $pAttributes, $ppSourceReader);
# pByteStream : IMFByteStream* -> LPVOID
# pAttributes : IMFAttributes* optional -> LPVOID
# ppSourceReader : IMFSourceReader** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型