rotation: compute proper display matrix rotation

Change-Id: I727a0040b4a80afa810db7b6042a3e7ec093f4b4
This commit is contained in:
Adrien Béraud
2019-11-06 14:17:19 -05:00
parent 48e487776b
commit 55e56b2832
6 changed files with 15 additions and 9 deletions

View File

@ -78,7 +78,7 @@ struct MediaRecorder::StreamObserver : public Observer<std::shared_ptr<MediaFram
if (info.isVideo) {
auto framePtr = static_cast<VideoFrame*>(m.get());
AVFrameSideData* sideData = av_frame_get_side_data(framePtr->pointer(), AV_FRAME_DATA_DISPLAYMATRIX);
int angle = sideData ? av_display_rotation_get(reinterpret_cast<int32_t*>(sideData->data)) : 0;
int angle = sideData ? -av_display_rotation_get(reinterpret_cast<int32_t*>(sideData->data)) : 0;
if (angle != rotation_) {
videoRotationFilter_ = jami::video::getTransposeFilter(angle, ROTATION_FILTER_INPUT_NAME, framePtr->width(), framePtr->height(), framePtr->format(), true);
rotation_ = angle;

View File

@ -367,7 +367,7 @@ SinkClient::update(Observable<std::shared_ptr<MediaFrame>>* /*obs*/,
int angle = 0;
if (side_data) {
auto matrix_rotation = reinterpret_cast<int32_t*>(side_data->data);
angle = av_display_rotation_get(matrix_rotation);
angle = -av_display_rotation_get(matrix_rotation);
}
if (angle != rotation_) {
filter_ = getTransposeFilter(angle, FILTER_INPUT_NAME, frame->width(), frame->height(), AV_PIX_FMT_RGB32, false);

View File

@ -208,7 +208,7 @@ VideoMixer::render_frame(VideoFrame& output, const VideoFrame& input,
int angle = 0;
if (sideData) {
auto matrixRotation = reinterpret_cast<int32_t*>(sideData->data);
angle = av_display_rotation_get(matrixRotation);
angle = -av_display_rotation_get(matrixRotation);
}
const constexpr char filterIn[] = "mixin";
if (angle != source->rotation) {

View File

@ -84,7 +84,7 @@ VideoSender::encodeAndSendVideo(VideoFrame& input_frame)
#endif
int size {0};
uint8_t* side_data = av_packet_get_side_data(packet, AV_PKT_DATA_DISPLAYMATRIX, &size);
auto angle = (side_data == nullptr || size == 0) ? 0 : av_display_rotation_get(reinterpret_cast<int32_t*>(side_data));
auto angle = (side_data == nullptr || size == 0) ? 0 : -av_display_rotation_get(reinterpret_cast<int32_t*>(side_data));
if (rotation_ != angle) {
rotation_ = angle;
if (changeOrientationCallback_)
@ -100,7 +100,7 @@ VideoSender::encodeAndSendVideo(VideoFrame& input_frame)
--forceKeyFrame_;
AVFrameSideData* side_data = av_frame_get_side_data(input_frame.pointer(), AV_FRAME_DATA_DISPLAYMATRIX);
auto angle = side_data == nullptr ? 0 : av_display_rotation_get(reinterpret_cast<int32_t*>(side_data->data));
auto angle = side_data == nullptr ? 0 : -av_display_rotation_get(reinterpret_cast<int32_t*>(side_data->data));
if (rotation_ != angle) {
rotation_ = angle;
if (changeOrientationCallback_)

View File

@ -702,7 +702,7 @@ SIPCall::setVideoOrientation(int rotation)
std::string sip_body =
"<?xml version=\"1.0\" encoding=\"utf-8\" ?>"
"<media_control><vc_primitive><to_encoder>"
"<device_orientation=" + std::to_string(rotation) + "/>"
"<device_orientation=" + std::to_string(-rotation) + "/>"
"</to_encoder></vc_primitive></media_control>";
JAMI_DBG("Sending device orientation via SIP INFO");

View File

@ -972,9 +972,15 @@ handleMediaControl(SIPCall& call, pjsip_msg_body* body)
std::regex_search(body_msg, matched_pattern, ORIENTATION_REGEX);
if (matched_pattern.ready() && !matched_pattern.empty() && matched_pattern[1].matched) {
int rotation = std::stoi(matched_pattern[1]);
JAMI_WARN("Rotate video %d deg.", rotation);
call.getVideoRtp().setRotation(rotation);
try {
int rotation = -std::stoi(matched_pattern[1]);
while (rotation <= -180) rotation += 360;
while (rotation > 180) rotation -= 360;
JAMI_WARN("Rotate video %d deg.", rotation);
call.getVideoRtp().setRotation(rotation);
} catch (const std::exception& e) {
JAMI_WARN("Error parsing angle: %s", e.what());
}
return true;
}
}