Skip to content
This repository was archived by the owner on Oct 23, 2024. It is now read-only.

setMaxResolution for adaptive video #699

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Apache License
Apache License!!!
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why adding this change to license and readme file?

Version 2.0, January 2004
http://www.apache.org/licenses/

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## Open WebRTC Toolkit Media Server
## Open WebRTC Toolkit Media Server!!!@@@

remove

The media server for OWT provides an efficient video conference and streaming service that is based on WebRTC. It scales a single WebRTC stream out to many endpoints. At the same time, it enables media analytics capabilities for media streams. It features:

Expand Down
Binary file added bad_44sec_10mb.mp4
Binary file not shown.
Binary file added bad_7s.mp4
Binary file not shown.
8 changes: 8 additions & 0 deletions scripts/release/daemon-bin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,14 @@ case $startStop in
fi
;;

(restart)
echo restarting $command

${0} stop $command
${0} start $command
;;


(status)
if [ -f $pid ]; then
if ps -p `cat $pid` > /dev/null 2>&1; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class VideoFrameTranscoder {
virtual void removeOutput(int output) = 0;

virtual void requestKeyFrame(int output) = 0;
virtual void setMaxResolution(int output, int width, int height) = 0;
#ifndef BUILD_FOR_ANALYTICS
virtual void drawText(const std::string& textSpec) = 0;
virtual void clearText() = 0;
Expand Down
10 changes: 10 additions & 0 deletions source/agent/video/videoTranscoder/VideoFrameTranscoderImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class VideoFrameTranscoderImpl : public VideoFrameTranscoder, public owt_base::F
void removeOutput(int output);

void requestKeyFrame(int output);
void setMaxResolution(int output, int width, int height);
#ifndef BUILD_FOR_ANALYTICS
void drawText(const std::string& textSpec);
void clearText();
Expand Down Expand Up @@ -283,6 +284,15 @@ inline void VideoFrameTranscoderImpl::requestKeyFrame(int output)
if (it != m_outputs.end())
it->second.encoder->requestKeyFrame(it->second.streamId);
}

inline void VideoFrameTranscoderImpl::setMaxResolution(int output, int width, int height)
{
boost::shared_lock<boost::shared_mutex> lock(m_outputMutex);
auto it = m_outputs.find(output);
if (it != m_outputs.end())
it->second.encoder->setMaxResolution(it->second.streamId, width, height);
}


#ifndef BUILD_FOR_ANALYTICS
inline void VideoFrameTranscoderImpl::drawText(const std::string& textSpec)
Expand Down
17 changes: 17 additions & 0 deletions source/agent/video/videoTranscoder/VideoTranscoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,23 @@ void VideoTranscoder::forceKeyFrame(const std::string& outStreamID)
m_frameTranscoder->requestKeyFrame(index);
}
}

void VideoTranscoder::setMaxResolution(const std::string& outStreamID, int width, int height)
{

int32_t index = -1;
boost::shared_lock<boost::shared_mutex> lock(m_outputsMutex);
auto it = m_outputs.find(outStreamID);
if (it != m_outputs.end()) {
index = it->second;
}
lock.unlock();

if (index != -1) {
m_frameTranscoder->setMaxResolution(index, width, height);
}
}

#ifndef BUILD_FOR_ANALYTICS
void VideoTranscoder::drawText(const std::string& textSpec)
{
Expand Down
1 change: 1 addition & 0 deletions source/agent/video/videoTranscoder/VideoTranscoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class VideoTranscoder {
#endif
void removeOutput(const std::string& outStreamID);
void forceKeyFrame(const std::string& outStreamID);
void setMaxResolution(const std::string& outStreamID, int width, int height);
#ifndef BUILD_FOR_ANALYTICS
void drawText(const std::string& textSpec);
void clearText();
Expand Down
20 changes: 20 additions & 0 deletions source/agent/video/videoTranscoder/VideoTranscoderWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,26 @@ void VideoTranscoder::forceKeyFrame(const v8::FunctionCallbackInfo<v8::Value>& a
me->forceKeyFrame(outStreamID);
}

void VideoTranscoder::setMaxResolution(const v8::FunctionCallbackInfo<v8::Value>& args){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is not registered in node layer through "init" function in line 24. Who will call this function?


Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);

VideoTranscoder* obj = ObjectWrap::Unwrap<VideoTranscoder>(args.Holder());
mcu::VideoTranscoder* me = obj->me;

String::Utf8Value param0(args[0]->ToString());
String::Utf8Value param1(args[1]->ToString());
String::Utf8Value param2(args[2]->ToString());

std::string outStreamID = std::string(*param0);
int width = std::stoi(std::string(*param1));
int height = std::stoi(std::string(*param2));

me->setMaxResolution(outStreamID, width, height);
}


#ifndef BUILD_FOR_ANALYTICS
void VideoTranscoder::drawText(const v8::FunctionCallbackInfo<v8::Value>& args) {
Isolate* isolate = Isolate::GetCurrent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class VideoTranscoder : public node::ObjectWrap {
static void addOutput(const v8::FunctionCallbackInfo<v8::Value>& args);
static void removeOutput(const v8::FunctionCallbackInfo<v8::Value>& args);
static void forceKeyFrame(const v8::FunctionCallbackInfo<v8::Value>& args);
static void setMaxResolution(const v8::FunctionCallbackInfo<v8::Value>& args);
#ifndef BUILD_FOR_ANLAYTICS
static void drawText(const v8::FunctionCallbackInfo<v8::Value>& args);
static void clearText(const v8::FunctionCallbackInfo<v8::Value>& args);
Expand Down
1 change: 1 addition & 0 deletions source/core/owt_base/AVStreamOut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ void AVStreamOut::onFrame(const owt_base::Frame& frame)
}

if (!m_videoSourceChanged
&& frame.additionalInfo.video.width != 0
&& (m_width != frame.additionalInfo.video.width || m_height != frame.additionalInfo.video.height)) {

ELOG_DEBUG("Video resolution changed %dx%d -> %dx%d",
Expand Down
12 changes: 12 additions & 0 deletions source/core/owt_base/MediaFramePipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,19 @@ class VideoFrameEncoder : public FrameDestination {
virtual void degenerateStream(int32_t streamId) = 0;
virtual void setBitrate(unsigned short kbps, int32_t streamId) = 0;
virtual void requestKeyFrame(int32_t streamId) = 0;

protected:
int maxWidth = 0;
int maxHeight = 0;
};


inline void VideoFrameEncoder::setMaxResolution(int output, int width, int height)
{
maxWidth = width;
maxHeight = height;
}


}
#endif
24 changes: 21 additions & 3 deletions source/core/owt_base/VCMFrameEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,16 +384,34 @@ void VCMFrameEncoder::encode(boost::shared_ptr<webrtc::VideoFrame> frame)
}

if (m_width != frame->width() || m_height != frame->height()) {
ELOG_DEBUG_T("Update encoder resolution %dx%d->%dx%d", m_width, m_height, frame->width(), frame->height());

ret = m_encoder->SetResolution(frame->width(), frame->height());
int new_width = 0;
int new_height = 0;

if(maxWidth > 0 && frame->width() > maxWidth){
new_width = maxWidth;
new_height = (int) ( static_cast<double>(new_width) / (static_cast<double>(frame->width()) / static_cast<double>(frame->height())) );
}else if(maxHeight > 0 && frame->height() > maxHeight){
new_height = maxHeight;
new_width = (int) ( static_cast<double>(new_height) * ( static_cast<double>(frame->width()) / static_cast<double>(frame->height()) ) );
}else{
new_width = frame->width();
new_height = frame->height();
}


ELOG_DEBUG_T("Update encoder resolution %dx%d, %dx%d->%dx%d", frame->width(), frame->height(), m_width, m_height, new_width, new_height);

ret = m_encoder->SetResolution(new_width, new_height);
if (ret != 0) {
ELOG_WARN_T("Update Encode size error: %d", ret);
}

m_width = frame->width();
m_height = frame->height();
m_updateBitrateKbps = calcBitrate(m_width, m_height, m_frameRate);

m_updateBitrateKbps = calcBitrate(new_width, new_height, m_frameRate);

}

if (m_updateBitrateKbps) {
Expand Down
2 changes: 1 addition & 1 deletion source/management_console/public/js/libapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function calculateSignature (toSign, key) {
function ManagementApi (spec) {
this.id = spec.id;
this.key = spec.key;
this.url = spec.url || '/';
this.url = spec.url || window.location.pathname.replace(/\/console.*/g, "/");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code conflict with latest master code

this.send = function (method, body, url, callback) { // callback (err, resp)
var service = this.id;
var key = this.key;
Expand Down