getVideoHeight(), getVideoWidth() and getVideoFps() in JPEGTrack

This commit is contained in:
Alexandr 2022-12-19 18:36:44 +03:00
parent fda69e2a8e
commit d4c88b4864
2 changed files with 27 additions and 2 deletions

View File

@ -6,6 +6,29 @@ using namespace toolkit;
namespace mediakit {
bool JPEGTrack::inputFrame(const Frame::Ptr &frame) {
if (!ready()) {
if ((_height & _width) > 0) {
if (_tmp == 0) _tmp = frame->dts();
else _fps = 1000.0 / (frame->dts() - _tmp);
} else getVideoResolution((uint8_t*)frame->data(), frame->size());
return false;
}
return VideoTrack::inputFrame(frame);
}
void JPEGTrack::getVideoResolution(const uint8_t *buf, int len) {
for (int i = 0; i < len - 8; i++) {
if (buf[i] != 0xff)
continue;
if (buf[i + 1] == 0xC0 /*SOF0*/) {
_height = buf[i + 5] * 256 + buf[i + 6];
_width = buf[i + 7] * 256 + buf[i + 8];
return;
}
}
}
class JPEGSdp : public Sdp {
public:
JPEGSdp(int bitrate): Sdp(90000, Rtsp::PT_JPEG) {

View File

@ -14,17 +14,19 @@ public:
int getVideoHeight() const override { return _height; }
int getVideoWidth() const override { return _width; }
float getVideoFps() const override { return _fps; }
bool ready() override { return true; }
bool inputFrame(const Frame::Ptr &frame) override { return VideoTrack::inputFrame(frame); }
bool ready() override { return _fps > 0; }
bool inputFrame(const Frame::Ptr &frame) override;
private:
Sdp::Ptr getSdp() override;
Track::Ptr clone() override { return std::make_shared<std::remove_reference<decltype(*this)>::type>(*this); }
void getVideoResolution(const uint8_t *buf, int len);
private:
int _width = 0;
int _height = 0;
float _fps = 0;
uint64_t _tmp = 0;
};
class JPEGFrame : public Frame {