提交 e936e666 authored 作者: José Luis Millán's avatar José Luis Millán

VP8: Key frame detection

上级 8f75544e
#ifndef MS_RTC_CODECS_HPP
#define MS_RTC_CODECS_HPP
#include "common.hpp"
#include "RTC/Codecs/VP8.hpp"
#include "RTC/RtpDictionaries.hpp"
#include "RTC/RtpPacket.hpp"
namespace RTC
{
namespace Codecs
{
bool isKnown(const RTC::RtpCodecMimeType& mimeType);
bool isKeyFrame(const RTC::RtpCodecMimeType& mimeType, const RTC::RtpPacket* packet);
} // namespace Codecs
} // namespace RTC
#endif
#ifndef MS_RTC_CODECS_VP8_HPP
#define MS_RTC_CODECS_VP8_HPP
#include "common.hpp"
namespace RTC
{
namespace Codecs
{
class VP8
{
public:
static bool isKeyFrame(const uint8_t* data, size_t len);
};
} // namespace Codecs
} // namespace RTC
#endif
...@@ -38,6 +38,7 @@ namespace RTC ...@@ -38,6 +38,7 @@ namespace RTC
virtual Json::Value ToJson() = 0; virtual Json::Value ToJson() = 0;
virtual bool ReceivePacket(RTC::RtpPacket* packet); virtual bool ReceivePacket(RTC::RtpPacket* packet);
uint32_t GetSsrc(); uint32_t GetSsrc();
const RTC::RtpCodecMimeType& GetMymeType() const;
bool IsHealthy(); bool IsHealthy();
protected: protected:
...@@ -82,6 +83,11 @@ namespace RTC ...@@ -82,6 +83,11 @@ namespace RTC
return this->params.ssrc; return this->params.ssrc;
} }
inline const RTC::RtpCodecMimeType& RtpStream::GetMymeType() const
{
return this->params.mime;
}
inline bool RtpStream::IsHealthy() inline bool RtpStream::IsHealthy()
{ {
return this->healthy; return this->healthy;
......
...@@ -41,6 +41,8 @@ ...@@ -41,6 +41,8 @@
'src/RTC/Transport.cpp', 'src/RTC/Transport.cpp',
'src/RTC/TransportTuple.cpp', 'src/RTC/TransportTuple.cpp',
'src/RTC/UdpSocket.cpp', 'src/RTC/UdpSocket.cpp',
'src/RTC/Codecs/Codecs.cpp',
'src/RTC/Codecs/VP8.cpp',
'src/RTC/RtpDictionaries/Media.cpp', 'src/RTC/RtpDictionaries/Media.cpp',
'src/RTC/RtpDictionaries/Parameters.cpp', 'src/RTC/RtpDictionaries/Parameters.cpp',
'src/RTC/RtpDictionaries/RtcpFeedback.cpp', 'src/RTC/RtpDictionaries/RtcpFeedback.cpp',
...@@ -129,6 +131,8 @@ ...@@ -129,6 +131,8 @@
'include/RTC/Transport.hpp', 'include/RTC/Transport.hpp',
'include/RTC/TransportTuple.hpp', 'include/RTC/TransportTuple.hpp',
'include/RTC/UdpSocket.hpp', 'include/RTC/UdpSocket.hpp',
'include/RTC/Codecs/Codecs.hpp',
'include/RTC/Codecs/VP8.hpp',
'include/RTC/RTCP/Packet.hpp', 'include/RTC/RTCP/Packet.hpp',
'include/RTC/RTCP/CompoundPacket.hpp', 'include/RTC/RTCP/CompoundPacket.hpp',
'include/RTC/RTCP/SenderReport.hpp', 'include/RTC/RTCP/SenderReport.hpp',
......
#define MS_CLASS "RTC::Codecs"
#define MS_LOG_DEV
#include "RTC/Codecs/Codecs.hpp"
#include "Logger.hpp"
#include "RTC/Codecs/VP8.hpp"
namespace RTC
{
namespace Codecs
{
bool isKnown(const RTC::RtpCodecMimeType& mimeType)
{
MS_TRACE();
if (mimeType.type != RTC::RtpCodecMimeType::Type::VIDEO)
return false;
switch (mimeType.subtype)
{
case RTC::RtpCodecMimeType::Subtype::VP8:
return true;
default:
return false;
}
}
bool isKeyFrame(const RTC::RtpCodecMimeType& mimeType, const RTC::RtpPacket* packet)
{
MS_TRACE();
if (!isKnown(mimeType))
return false;
auto data = packet->GetPayload();
auto len = packet->GetPayloadLength();
switch (mimeType.subtype)
{
case RTC::RtpCodecMimeType::Subtype::VP8:
return VP8::isKeyFrame(data, len);
default:
MS_DEBUG_TAG(
rtp, "requested key frame for an unsupported codec: %s", mimeType.GetName().c_str());
return false;
}
}
} // namespace Codecs
} // namespace RTC
#define MS_CLASS "RTC::Codecs::VP8"
#define MS_LOG_DEV
#include "RTC/Codecs/VP8.hpp"
#include "Logger.hpp"
#include "Utils.hpp"
namespace RTC
{
namespace Codecs
{
bool VP8::isKeyFrame(const uint8_t* data, size_t len)
{
if (len < 1)
return false;
size_t offset = 0;
uint8_t byte = data[offset++];
uint8_t x = (byte >> 7) & 0x1;
uint8_t start = (byte >> 4) & 0x1;
uint8_t pid = byte & 0x07;
uint8_t i = 0;
uint8_t l = 0;
uint8_t t = 0;
uint8_t k = 0;
if (x)
{
{
if (len < offset + 1)
return false;
}
byte = data[offset++];
i = (byte >> 7) & 0x1;
l = (byte >> 6) & 0x1;
t = (byte >> 5) & 0x1;
k = (byte >> 4) & 0x1;
}
if (i)
{
if (len < offset++)
{
return false;
}
if ((byte >> 7) & 0x1)
{
if (len < offset++)
return false;
}
}
if (l)
{
if (len < offset++)
{
return false;
}
}
if (t || k)
{
if (len < offset++)
{
return false;
}
}
return start && pid == 0 && (!(data[offset] & 0x1));
}
} // namespace Codecs
} // namespace RTC
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论