Problem with IWMVideoMediaProps & SetMediaType
WMPTalk.com Forum Index WMPTalk.com
Discuss Windows Media Player
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web wmptalk.com
Problem with IWMVideoMediaProps & SetMediaType

 
Post new topic   Reply to topic    WMPTalk.com Forum Index -> SDK
Author Message
Ramon Bisswanger
Guest





Posted: Thu Sep 30, 2004 1:58 pm    Post subject: Problem with IWMVideoMediaProps & SetMediaType Reply with quote

I've a problem setting a media type to a stream.
I've ported some code to Delphi.
When trying to set the media type I always get NS_E_INVALID_STREAM.

Has anyone an idea?

Thanks in advance,
Ramon

Here the code:

function CreateVideoStream: String;
var
hr: HRESULT;
pProps: IWMVideoMediaProps;
pPropertyVault: IWMPropertyVault;
pMediaType: WM_MEDIA_TYPE;
begin
Result := '';
hr := pProfile.CreateNewStream(WMMEDIATYPE_Video, pVideoStream);
if FAILED(hr) then begin
Result := 'Could not create Video stream. (Error #801)';
exit;
end;
hr := pVideoStream.SetBitrate(Profiles[ActiveProfile].VideoBitrate);
if FAILED(hr) then begin
Result := 'Could not set bitrate for Video stream. (Error #802)';
exit;
end;
hr := pVideoStream.SetBufferWindow(Profiles[ActiveProfile].VideoBuffer);
if FAILED(hr) then begin
Result := 'Could not set buffer window for Video stream. (Error
#803)';
exit;
end;
Result := CreateVideoMediaType(@pMediaType);
If Result <> '' then exit;
hr := pVideoStream.QueryInterface(IID_IWMVideoMediaProps, pProps);
if FAILED(hr) then begin
Result := 'Could not QI for IWMMediaProp on video stream. (Error
#804)';
exit;
end;

hr := pProps.SetMediaType(@pMediaType);
// RETURNS NS_E_INVALID_STREAM

if FAILED(hr) then begin
Result := 'Could not set media type for video stream. (Error
#805)'+#13+IntToStr(hr);
exit;
end;
hr := pProps.SetQuality(Profiles[ActiveProfile].Quality);
if FAILED(hr) then begin
Result := 'Could not set Quality. (Error #806)';
exit;
end;
hr := pProps.SetMaxKeyFrameSpacing(Profiles[ActiveProfile].KeyFrame *
10000000);
if FAILED(hr) then begin
Result := 'Could not set MaxKeyFrameSpacing. (Error #807)';
exit;
end;
hr := pVideoStream.QueryInterface(IID_IWMPropertyVault,
pPropertyVault);
if FAILED(hr) then begin
Result := 'Could not QI for IWMPropertyVaul on video stream.
(Error #808)';
exit;
end;
Result := SetStreamLanguage(pVideoStream,
Profiles[ActiveProfile].VideoLanguage);
If Result <> '' then exit;
hr := pVideoStream.SetStreamNumber(2);
if FAILED(hr) then begin
Result := 'Could not set stream number for Video stream. (Error
#810)';
exit;
end;
hr := pVideoStream.SetStreamName('DVB Video Input');
if FAILED(hr) then begin
Result := 'Could not set name for Video stream. (Error #811)';
exit;
end;
hr := pProfile.AddStream(pVideoStream);
if FAILED(hr) then begin
Result := 'Could not add Video stream to profile. (Error #812)';
exit;
end;
end;

function CreateVideoMediaType(ppmtMediaType: PWMMediaType): String;
var
pVIH: PWMVIDEOINFOHEADER;
hr: HRESULT;
fIsVBR: Boolean;
pFormatConfig: IWMStreamConfig;
pMediaProps: IWMMediaProps;
dwMediaTypeLength: DWORD;
begin
Result := '';
fIsVBR := False;
hr := pCodecInfo.SetCodecEnumerationSetting(WMMEDIATYPE_Video,
Profiles[ActiveProfile].VideoCodecNr, g_wszVBREnabled, WMT_TYPE_BOOL,
@fIsVBR, sizeof( BOOL ));
If FAILED(hr) then begin
Result := ' Can not set VBR setting for video codec. (Error
#851)';
exit;
end;
hr := pCodecInfo.GetCodecFormat(WMMEDIATYPE_Video,
Profiles[ActiveProfile].VideoCodecNr, 0, pFormatConfig);
If FAILED(hr) then begin
Result := ' Failed to get codec format for video codec. (Error
#852)';
exit;
end;
hr := pFormatConfig.QueryInterface(IID_IWMMediaProps, pMediaProps);
If FAILED(hr) then begin
Result := ' Failed to QI for IWMMediaProps on pFormatConfig.
(Error #853)';
exit;
end;
dwMediaTypeLength := 0;
hr := pMediaProps.GetMediaType(nil, dwMediaTypeLength);
If FAILED(hr) then begin
Result := ' Failed to get media type length video codec. (Error
#854)';
exit;
end;
ppmtMediaType := PWMMediaType(AllocMem(dwMediaTypeLength));
hr := pMediaProps.GetMediaType(ppmtMediaType, dwMediaTypeLength);
If FAILED(hr) then begin
Result := ' Failed to get media type for video codec. (Error
#855)';
exit;
end;
pVIH := @ppmtMediaType^.pbFormat;
pVIH.dwBitRate := Profiles[ActiveProfile].VideoBitrate;
pVIH.rcSource.right := Profiles[ActiveProfile].VideoWidth;
pVIH.rcSource.bottom := Profiles[ActiveProfile].VideoHeight;
pVIH.rcTarget.right := Profiles[ActiveProfile].VideoWidth;
pVIH.rcTarget.bottom := Profiles[ActiveProfile].VideoHeight;
pVIH.bmiHeader.biWidth := Profiles[ActiveProfile].VideoWidth;
pVIH.bmiHeader.biHeight := Profiles[ActiveProfile].VideoHeight;
pVIH.AvgTimePerFrame := (10000000 div
Profiles[ActiveProfile].VideoFrames);
end;

Back to top
Becky Weiss [MS]
Guest





Posted: Sat Oct 02, 2004 5:49 am    Post subject: RE: Problem with IWMVideoMediaProps & SetMediaType Reply with quote

Ramon,

It looks like you're calling SetMediaType before you've set all the
WMVIDEOINFOHEADER fields (which describe the dimensions of the video and
other interesting stuff). These need to be set before you set the Media
Type. Setting this stuff on the Media Type after SetMediaType has no effect.

Becky

This posting is provided AS IS with no warranties and confers no rights.

"Ramon Bisswanger" wrote:

Quote:
I've a problem setting a media type to a stream.
I've ported some code to Delphi.
When trying to set the media type I always get NS_E_INVALID_STREAM.

Has anyone an idea?

Thanks in advance,
Ramon

Here the code:

function CreateVideoStream: String;
var
hr: HRESULT;
pProps: IWMVideoMediaProps;
pPropertyVault: IWMPropertyVault;
pMediaType: WM_MEDIA_TYPE;
begin
Result := '';
hr := pProfile.CreateNewStream(WMMEDIATYPE_Video, pVideoStream);
if FAILED(hr) then begin
Result := 'Could not create Video stream. (Error #801)';
exit;
end;
hr := pVideoStream.SetBitrate(Profiles[ActiveProfile].VideoBitrate);
if FAILED(hr) then begin
Result := 'Could not set bitrate for Video stream. (Error #802)';
exit;
end;
hr := pVideoStream.SetBufferWindow(Profiles[ActiveProfile].VideoBuffer);
if FAILED(hr) then begin
Result := 'Could not set buffer window for Video stream. (Error
#803)';
exit;
end;
Result := CreateVideoMediaType(@pMediaType);
If Result <> '' then exit;
hr := pVideoStream.QueryInterface(IID_IWMVideoMediaProps, pProps);
if FAILED(hr) then begin
Result := 'Could not QI for IWMMediaProp on video stream. (Error
#804)';
exit;
end;

hr := pProps.SetMediaType(@pMediaType);
// RETURNS NS_E_INVALID_STREAM

if FAILED(hr) then begin
Result := 'Could not set media type for video stream. (Error
#805)'+#13+IntToStr(hr);
exit;
end;
hr := pProps.SetQuality(Profiles[ActiveProfile].Quality);
if FAILED(hr) then begin
Result := 'Could not set Quality. (Error #806)';
exit;
end;
hr := pProps.SetMaxKeyFrameSpacing(Profiles[ActiveProfile].KeyFrame *
10000000);
if FAILED(hr) then begin
Result := 'Could not set MaxKeyFrameSpacing. (Error #807)';
exit;
end;
hr := pVideoStream.QueryInterface(IID_IWMPropertyVault,
pPropertyVault);
if FAILED(hr) then begin
Result := 'Could not QI for IWMPropertyVaul on video stream.
(Error #808)';
exit;
end;
Result := SetStreamLanguage(pVideoStream,
Profiles[ActiveProfile].VideoLanguage);
If Result <> '' then exit;
hr := pVideoStream.SetStreamNumber(2);
if FAILED(hr) then begin
Result := 'Could not set stream number for Video stream. (Error
#810)';
exit;
end;
hr := pVideoStream.SetStreamName('DVB Video Input');
if FAILED(hr) then begin
Result := 'Could not set name for Video stream. (Error #811)';
exit;
end;
hr := pProfile.AddStream(pVideoStream);
if FAILED(hr) then begin
Result := 'Could not add Video stream to profile. (Error #812)';
exit;
end;
end;

function CreateVideoMediaType(ppmtMediaType: PWMMediaType): String;
var
pVIH: PWMVIDEOINFOHEADER;
hr: HRESULT;
fIsVBR: Boolean;
pFormatConfig: IWMStreamConfig;
pMediaProps: IWMMediaProps;
dwMediaTypeLength: DWORD;
begin
Result := '';
fIsVBR := False;
hr := pCodecInfo.SetCodecEnumerationSetting(WMMEDIATYPE_Video,
Profiles[ActiveProfile].VideoCodecNr, g_wszVBREnabled, WMT_TYPE_BOOL,
@fIsVBR, sizeof( BOOL ));
If FAILED(hr) then begin
Result := ' Can not set VBR setting for video codec. (Error
#851)';
exit;
end;
hr := pCodecInfo.GetCodecFormat(WMMEDIATYPE_Video,
Profiles[ActiveProfile].VideoCodecNr, 0, pFormatConfig);
If FAILED(hr) then begin
Result := ' Failed to get codec format for video codec. (Error
#852)';
exit;
end;
hr := pFormatConfig.QueryInterface(IID_IWMMediaProps, pMediaProps);
If FAILED(hr) then begin
Result := ' Failed to QI for IWMMediaProps on pFormatConfig.
(Error #853)';
exit;
end;
dwMediaTypeLength := 0;
hr := pMediaProps.GetMediaType(nil, dwMediaTypeLength);
If FAILED(hr) then begin
Result := ' Failed to get media type length video codec. (Error
#854)';
exit;
end;
ppmtMediaType := PWMMediaType(AllocMem(dwMediaTypeLength));
hr := pMediaProps.GetMediaType(ppmtMediaType, dwMediaTypeLength);
If FAILED(hr) then begin
Result := ' Failed to get media type for video codec. (Error
#855)';
exit;
end;
pVIH := @ppmtMediaType^.pbFormat;
pVIH.dwBitRate := Profiles[ActiveProfile].VideoBitrate;
pVIH.rcSource.right := Profiles[ActiveProfile].VideoWidth;
pVIH.rcSource.bottom := Profiles[ActiveProfile].VideoHeight;
pVIH.rcTarget.right := Profiles[ActiveProfile].VideoWidth;
pVIH.rcTarget.bottom := Profiles[ActiveProfile].VideoHeight;
pVIH.bmiHeader.biWidth := Profiles[ActiveProfile].VideoWidth;
pVIH.bmiHeader.biHeight := Profiles[ActiveProfile].VideoHeight;
pVIH.AvgTimePerFrame := (10000000 div
Profiles[ActiveProfile].VideoFrames);
end;
Back to top
 
Post new topic   Reply to topic    WMPTalk.com Forum Index -> SDK All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



Microsoft Office Forum New Topics
Powered by phpBB