Skip to content

Commit

Permalink
Expose IsActive and HDR information for Audio and Video stream infos (#…
Browse files Browse the repository at this point in the history
…444)

* expose IsActive and IsHdr to Audio and video stream info

* implement IsHdrActive and HasHdrMetadata

* add codecPar conditions

---------

Co-authored-by: Brabebhin <mihaicosmin2007@outlook.com>
  • Loading branch information
brabebhin and Brabebhin authored Nov 27, 2024
1 parent de96b62 commit 8b320d1
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 10 deletions.
12 changes: 12 additions & 0 deletions Source/AudioStreamInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,24 @@ namespace winrt::FFmpegInteropX::implementation
int64_t Bitrate();
bool IsDefault();
int32_t StreamIndex();
bool IsActive()
{
return active;
}

public:
bool SetDefault()
{
isDefault = true;
return isDefault;
}

bool SetIsActive(bool value)
{
active = value;
return active;
}

private:
hstring name{};
hstring language{};
Expand All @@ -42,6 +53,7 @@ namespace winrt::FFmpegInteropX::implementation

FFmpegInteropX::DecoderEngine decoderEngine;
int streamIndex = -1;
bool active = false;
};
}
namespace winrt::FFmpegInteropX::factory_implementation
Expand Down
9 changes: 9 additions & 0 deletions Source/FFmpegInteropX.idl
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ namespace FFmpegInteropX
Int32 BitsPerSample{ get; };

DecoderEngine DecoderEngine{ get; };

Boolean IsActive{ get; };
};

#ifdef UWP
Expand Down Expand Up @@ -178,6 +180,13 @@ namespace FFmpegInteropX

HardwareDecoderStatus HardwareDecoderStatus{ get; };
DecoderEngine DecoderEngine{ get; };
Boolean IsActive{ get; };

///<summary>The video has HDR metadata. This value is always false if DecoderEngine is SystemDecoder.</summary>
Boolean HasHdrMetadata{ get; };

///<summary>HDR is enabled for this stream. This value is always false if DecoderEngine is SystemDecoder.</summary>
Boolean IsHdrActive{ get; };
};

#ifdef UWP
Expand Down
2 changes: 1 addition & 1 deletion Source/FFmpegMediaSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1943,8 +1943,8 @@ namespace winrt::FFmpegInteropX::implementation
break;
default:
break;
}
}
}

std::shared_ptr<MediaSampleProvider> FFmpegMediaSource::CreateVideoSampleProvider(AVStream* avStream, AVCodecContext* avVideoCodecCtx, int index)
{
Expand Down
17 changes: 14 additions & 3 deletions Source/MediaSampleProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ void MediaSampleProvider::InitializeStreamInfo()
delete[] channelLayoutName;
}

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

Expand All @@ -210,7 +210,7 @@ void MediaSampleProvider::InitializeStreamInfo()
auto bitsPerSample = max(m_pAvStream->codecpar->bits_per_raw_sample, m_pAvStream->codecpar->bits_per_coded_sample);
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;

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

Expand Down Expand Up @@ -380,13 +380,24 @@ void MediaSampleProvider::EnableStream()
DebugMessage(L"EnableStream\n");
m_isEnabled = true;
m_pAvStream->discard = AVDISCARD_DEFAULT;

if (audioStreamInfo)
audioStreamInfo.as<implementation::AudioStreamInfo>()->SetIsActive(true);
if (videoStreamInfo)
videoStreamInfo.as<implementation::VideoStreamInfo>()->SetIsActive(true);

}

void MediaSampleProvider::DisableStream()
{
DebugMessage(L"DisableStream\n");
m_isEnabled = false;
m_pAvStream->discard = AVDISCARD_ALL;

if (audioStreamInfo)
audioStreamInfo.as<implementation::AudioStreamInfo>()->SetIsActive(false);
if (videoStreamInfo)
videoStreamInfo.as<implementation::VideoStreamInfo>()->SetIsActive(false);
}

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

void free_buffer(void* lpVoid)
{
auto buffer = (AVBufferRef *)lpVoid;
auto buffer = (AVBufferRef*)lpVoid;
av_buffer_unref(&buffer);
}
3 changes: 2 additions & 1 deletion Source/MediaSampleProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ class MediaSampleProvider
DecoderEngine decoder = DecoderEngine::FFmpegSoftwareDecoder;
winrt::com_ptr<ID3D11Device> device = NULL;
winrt::com_ptr<ID3D11DeviceContext> deviceContext = NULL;

AudioStreamInfo audioStreamInfo = NULL;
VideoStreamInfo videoStreamInfo = NULL;
};

// free AVBufferRef*
Expand Down
5 changes: 4 additions & 1 deletion Source/UncompressedVideoSampleProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ IMediaStreamDescriptor UncompressedVideoSampleProvider::CreateStreamDescriptor()
}
}

hasHdrMetadata = (masteringDisplayMetadata != nullptr && (masteringDisplayMetadata->has_primaries || masteringDisplayMetadata->has_luminance)) || contentLightMetadata != nullptr || codecPar->color_primaries >= MFVideoPrimaries_BT2020 || codecPar->color_trc >= MFVideoTransFunc_2020_const;
isHdrActive = hasHdrMetadata && applyHdrColorInfo;

videoProperties.Properties().Insert(MF_MT_INTERLACE_MODE, winrt::box_value((UINT32)_MFVideoInterlaceMode::MFVideoInterlace_MixedInterlaceOrProgressive));

return VideoStreamDescriptor(videoProperties);
Expand Down Expand Up @@ -747,7 +750,7 @@ void UncompressedVideoSampleProvider::CheckFrameSize(AVFrame* avFrame)
outputHeight = avFrame->height;
outputFrameWidth = frameWidth;
outputFrameHeight = frameHeight;

encProp.Width(outputFrameWidth);
encProp.Height(outputFrameHeight);

Expand Down
12 changes: 12 additions & 0 deletions Source/UncompressedVideoSampleProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ class UncompressedVideoSampleProvider : public UncompressedSampleProvider
UncompressedSampleProvider::NotifyCreateSource();
}

virtual void InitializeStreamInfo() override
{
MediaSampleProvider::InitializeStreamInfo();

auto videoStreamInfoImpl = videoStreamInfo.as<implementation::VideoStreamInfo>();

videoStreamInfoImpl->SetHasHdrMetadata(hasHdrMetadata);
videoStreamInfoImpl->SetIsHdrActive(isHdrActive);
}

private:
void SelectOutputFormat();
HRESULT InitializeScalerIfRequired(AVFrame* avFrame);
Expand Down Expand Up @@ -112,5 +122,7 @@ class UncompressedVideoSampleProvider : public UncompressedSampleProvider
winrt::Windows::Foundation::IInspectable minLuminance = { nullptr };
winrt::Windows::Foundation::IInspectable maxLuminance = { nullptr };
winrt::Windows::Foundation::IInspectable customPrimaries = { nullptr };
bool hasHdrMetadata = false;
bool isHdrActive = false;
};

46 changes: 42 additions & 4 deletions Source/VideoStreamInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,45 @@ namespace winrt::FFmpegInteropX::implementation
bool IsDefault();
int32_t StreamIndex();

bool IsActive()
{
return active;
}

bool HasHdrMetadata()
{
return hasHdrMetadata;
}

bool IsHdrActive()
{
return isHdrActive;
}

public:
bool SetDefault()
{
isDefault = true;
return isDefault;
}

void SetIsActive(bool value)
{
active = value;
}

bool SetHasHdrMetadata(bool value)
{
hasHdrMetadata = value;
return hasHdrMetadata;
}

bool SetIsHdrActive(bool value)
{
isHdrActive = value;
return isHdrActive;
}

hstring name{};
hstring language{};
hstring codecName{};
Expand All @@ -46,10 +84,10 @@ namespace winrt::FFmpegInteropX::implementation
FFmpegInteropX::HardwareDecoderStatus hardwareDecoderStatus;
FFmpegInteropX::DecoderEngine decoderEngine;
int streamIndex = -1;
void SetDefault()
{
isDefault = true;
}
private:
bool active = false;
bool hasHdrMetadata = false;
bool isHdrActive = false;
};
}
namespace winrt::FFmpegInteropX::factory_implementation
Expand Down

0 comments on commit 8b320d1

Please sign in to comment.