Skip to content

Commit 8b320d1

Browse files
brabebhinBrabebhin
and
Brabebhin
authored
Expose IsActive and HDR information for Audio and Video stream infos (#444)
* expose IsActive and IsHdr to Audio and video stream info * implement IsHdrActive and HasHdrMetadata * add codecPar conditions --------- Co-authored-by: Brabebhin <[email protected]>
1 parent de96b62 commit 8b320d1

8 files changed

+96
-10
lines changed

Source/AudioStreamInfo.h

+12
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,24 @@ namespace winrt::FFmpegInteropX::implementation
2020
int64_t Bitrate();
2121
bool IsDefault();
2222
int32_t StreamIndex();
23+
bool IsActive()
24+
{
25+
return active;
26+
}
27+
2328
public:
2429
bool SetDefault()
2530
{
2631
isDefault = true;
2732
return isDefault;
2833
}
2934

35+
bool SetIsActive(bool value)
36+
{
37+
active = value;
38+
return active;
39+
}
40+
3041
private:
3142
hstring name{};
3243
hstring language{};
@@ -42,6 +53,7 @@ namespace winrt::FFmpegInteropX::implementation
4253

4354
FFmpegInteropX::DecoderEngine decoderEngine;
4455
int streamIndex = -1;
56+
bool active = false;
4557
};
4658
}
4759
namespace winrt::FFmpegInteropX::factory_implementation

Source/FFmpegInteropX.idl

+9
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ namespace FFmpegInteropX
139139
Int32 BitsPerSample{ get; };
140140

141141
DecoderEngine DecoderEngine{ get; };
142+
143+
Boolean IsActive{ get; };
142144
};
143145

144146
#ifdef UWP
@@ -178,6 +180,13 @@ namespace FFmpegInteropX
178180

179181
HardwareDecoderStatus HardwareDecoderStatus{ get; };
180182
DecoderEngine DecoderEngine{ get; };
183+
Boolean IsActive{ get; };
184+
185+
///<summary>The video has HDR metadata. This value is always false if DecoderEngine is SystemDecoder.</summary>
186+
Boolean HasHdrMetadata{ get; };
187+
188+
///<summary>HDR is enabled for this stream. This value is always false if DecoderEngine is SystemDecoder.</summary>
189+
Boolean IsHdrActive{ get; };
181190
};
182191

183192
#ifdef UWP

Source/FFmpegMediaSource.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1943,8 +1943,8 @@ namespace winrt::FFmpegInteropX::implementation
19431943
break;
19441944
default:
19451945
break;
1946+
}
19461947
}
1947-
}
19481948

19491949
std::shared_ptr<MediaSampleProvider> FFmpegMediaSource::CreateVideoSampleProvider(AVStream* avStream, AVCodecContext* avVideoCodecCtx, int index)
19501950
{

Source/MediaSampleProvider.cpp

+14-3
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ void MediaSampleProvider::InitializeStreamInfo()
196196
delete[] channelLayoutName;
197197
}
198198

199-
streamInfo = AudioStreamInfo(
199+
streamInfo = audioStreamInfo = AudioStreamInfo(
200200
Name, Language, CodecName, (StreamDisposition)m_pAvStream->disposition, m_pAvStream->codecpar->bit_rate, false,
201201
channels, channelLayout, m_pAvStream->codecpar->sample_rate, bitsPerSample, Decoder(), StreamIndex());
202202

@@ -210,7 +210,7 @@ void MediaSampleProvider::InitializeStreamInfo()
210210
auto bitsPerSample = max(m_pAvStream->codecpar->bits_per_raw_sample, m_pAvStream->codecpar->bits_per_coded_sample);
211211
auto framesPerSecond = m_pAvStream->avg_frame_rate.num > 0 && m_pAvStream->avg_frame_rate.den > 0 ? av_q2d(m_pAvStream->avg_frame_rate) : 0.0;
212212

213-
streamInfo = VideoStreamInfo(Name, Language, CodecName, (StreamDisposition)m_pAvStream->disposition, m_pAvStream->codecpar->bit_rate, false,
213+
streamInfo = videoStreamInfo = VideoStreamInfo(Name, Language, CodecName, (StreamDisposition)m_pAvStream->disposition, m_pAvStream->codecpar->bit_rate, false,
214214
m_pAvStream->codecpar->width, m_pAvStream->codecpar->height, videoAspect,
215215
bitsPerSample, framesPerSecond, HardwareAccelerationStatus(), Decoder(), StreamIndex());
216216

@@ -380,13 +380,24 @@ void MediaSampleProvider::EnableStream()
380380
DebugMessage(L"EnableStream\n");
381381
m_isEnabled = true;
382382
m_pAvStream->discard = AVDISCARD_DEFAULT;
383+
384+
if (audioStreamInfo)
385+
audioStreamInfo.as<implementation::AudioStreamInfo>()->SetIsActive(true);
386+
if (videoStreamInfo)
387+
videoStreamInfo.as<implementation::VideoStreamInfo>()->SetIsActive(true);
388+
383389
}
384390

385391
void MediaSampleProvider::DisableStream()
386392
{
387393
DebugMessage(L"DisableStream\n");
388394
m_isEnabled = false;
389395
m_pAvStream->discard = AVDISCARD_ALL;
396+
397+
if (audioStreamInfo)
398+
audioStreamInfo.as<implementation::AudioStreamInfo>()->SetIsActive(false);
399+
if (videoStreamInfo)
400+
videoStreamInfo.as<implementation::VideoStreamInfo>()->SetIsActive(false);
390401
}
391402

392403
void MediaSampleProvider::SetCommonVideoEncodingProperties(VideoEncodingProperties const& videoProperties, bool isCompressedFormat)
@@ -481,6 +492,6 @@ void MediaSampleProvider::Detach()
481492

482493
void free_buffer(void* lpVoid)
483494
{
484-
auto buffer = (AVBufferRef *)lpVoid;
495+
auto buffer = (AVBufferRef*)lpVoid;
485496
av_buffer_unref(&buffer);
486497
}

Source/MediaSampleProvider.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ class MediaSampleProvider
225225
DecoderEngine decoder = DecoderEngine::FFmpegSoftwareDecoder;
226226
winrt::com_ptr<ID3D11Device> device = NULL;
227227
winrt::com_ptr<ID3D11DeviceContext> deviceContext = NULL;
228-
228+
AudioStreamInfo audioStreamInfo = NULL;
229+
VideoStreamInfo videoStreamInfo = NULL;
229230
};
230231

231232
// free AVBufferRef*

Source/UncompressedVideoSampleProvider.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,9 @@ IMediaStreamDescriptor UncompressedVideoSampleProvider::CreateStreamDescriptor()
271271
}
272272
}
273273

274+
hasHdrMetadata = (masteringDisplayMetadata != nullptr && (masteringDisplayMetadata->has_primaries || masteringDisplayMetadata->has_luminance)) || contentLightMetadata != nullptr || codecPar->color_primaries >= MFVideoPrimaries_BT2020 || codecPar->color_trc >= MFVideoTransFunc_2020_const;
275+
isHdrActive = hasHdrMetadata && applyHdrColorInfo;
276+
274277
videoProperties.Properties().Insert(MF_MT_INTERLACE_MODE, winrt::box_value((UINT32)_MFVideoInterlaceMode::MFVideoInterlace_MixedInterlaceOrProgressive));
275278

276279
return VideoStreamDescriptor(videoProperties);
@@ -747,7 +750,7 @@ void UncompressedVideoSampleProvider::CheckFrameSize(AVFrame* avFrame)
747750
outputHeight = avFrame->height;
748751
outputFrameWidth = frameWidth;
749752
outputFrameHeight = frameHeight;
750-
753+
751754
encProp.Width(outputFrameWidth);
752755
encProp.Height(outputFrameHeight);
753756

Source/UncompressedVideoSampleProvider.h

+12
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ class UncompressedVideoSampleProvider : public UncompressedSampleProvider
8282
UncompressedSampleProvider::NotifyCreateSource();
8383
}
8484

85+
virtual void InitializeStreamInfo() override
86+
{
87+
MediaSampleProvider::InitializeStreamInfo();
88+
89+
auto videoStreamInfoImpl = videoStreamInfo.as<implementation::VideoStreamInfo>();
90+
91+
videoStreamInfoImpl->SetHasHdrMetadata(hasHdrMetadata);
92+
videoStreamInfoImpl->SetIsHdrActive(isHdrActive);
93+
}
94+
8595
private:
8696
void SelectOutputFormat();
8797
HRESULT InitializeScalerIfRequired(AVFrame* avFrame);
@@ -112,5 +122,7 @@ class UncompressedVideoSampleProvider : public UncompressedSampleProvider
112122
winrt::Windows::Foundation::IInspectable minLuminance = { nullptr };
113123
winrt::Windows::Foundation::IInspectable maxLuminance = { nullptr };
114124
winrt::Windows::Foundation::IInspectable customPrimaries = { nullptr };
125+
bool hasHdrMetadata = false;
126+
bool isHdrActive = false;
115127
};
116128

Source/VideoStreamInfo.h

+42-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,45 @@ namespace winrt::FFmpegInteropX::implementation
2929
bool IsDefault();
3030
int32_t StreamIndex();
3131

32+
bool IsActive()
33+
{
34+
return active;
35+
}
36+
37+
bool HasHdrMetadata()
38+
{
39+
return hasHdrMetadata;
40+
}
41+
42+
bool IsHdrActive()
43+
{
44+
return isHdrActive;
45+
}
46+
3247
public:
48+
bool SetDefault()
49+
{
50+
isDefault = true;
51+
return isDefault;
52+
}
53+
54+
void SetIsActive(bool value)
55+
{
56+
active = value;
57+
}
58+
59+
bool SetHasHdrMetadata(bool value)
60+
{
61+
hasHdrMetadata = value;
62+
return hasHdrMetadata;
63+
}
64+
65+
bool SetIsHdrActive(bool value)
66+
{
67+
isHdrActive = value;
68+
return isHdrActive;
69+
}
70+
3371
hstring name{};
3472
hstring language{};
3573
hstring codecName{};
@@ -46,10 +84,10 @@ namespace winrt::FFmpegInteropX::implementation
4684
FFmpegInteropX::HardwareDecoderStatus hardwareDecoderStatus;
4785
FFmpegInteropX::DecoderEngine decoderEngine;
4886
int streamIndex = -1;
49-
void SetDefault()
50-
{
51-
isDefault = true;
52-
}
87+
private:
88+
bool active = false;
89+
bool hasHdrMetadata = false;
90+
bool isHdrActive = false;
5391
};
5492
}
5593
namespace winrt::FFmpegInteropX::factory_implementation

0 commit comments

Comments
 (0)