mirror of
https://git.jami.net/savoirfairelinux/jami-daemon.git
synced 2025-08-12 22:09:25 +08:00
rotation: compute proper display matrix rotation
Change-Id: I727a0040b4a80afa810db7b6042a3e7ec093f4b4
This commit is contained in:
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
@ -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_)
|
||||
|
@ -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");
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user