Skip to content

Commit

Permalink
Videoswitching fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
silverchris committed Jul 23, 2022
1 parent 2d04848 commit 9438067
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 73 deletions.
7 changes: 2 additions & 5 deletions include/autoapp/Managers/AAPA.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ class AAPA {
std::shared_ptr<com_jci_aapaInterface> adapter;
AADBus *androiddbus;
std::shared_ptr<com_jci_bucpsa_objectProxy> bucpsa;
bool hasFocus;
bool waitsForFocus;
bool _connected = false;


Expand All @@ -64,10 +62,9 @@ class AAPA {
const std::shared_ptr<DBus::Connection> &session_connection);
~AAPA();

void requestFocus(VIDEO_FOCUS_REQUESTOR requestor);
void releaseFocus(VIDEO_FOCUS_REQUESTOR requestor);
void requestFocus();
void releaseFocus();

void DisplayMode(uint32_t DisplayMode);
void FocusChange(bool focus);
void AAConnected(bool connected);
};
4 changes: 2 additions & 2 deletions include/autoapp/Managers/VideoManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class VideoManager {
explicit VideoManager(VideoSignals::Pointer videosignals, const std::shared_ptr<DBus::Connection> &);
~VideoManager();

void requestFocus(VIDEO_FOCUS_REQUESTOR requestor);
void releaseFocus(VIDEO_FOCUS_REQUESTOR requestor);
void requestFocus();
void releaseFocus();

enum SURFACES {
NNG_NAVI_ID = 0,
Expand Down
10 changes: 5 additions & 5 deletions include/autoapp/Service/VideoService.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ class VideoService
void onVideoFocusRequest(const aasdk::proto::messages::VideoFocusRequest &request) override;
void onChannelError(const aasdk::error::Error &e) override;

VideoSignals::Pointer videoSignals_;

private:
using std::enable_shared_from_this<VideoService>::shared_from_this;
void sendVideoFocusIndication(VIDEO_FOCUS_REQUESTOR requestor);
void sendVideoFocusLost(VIDEO_FOCUS_REQUESTOR requestor);
void sendVideoFocusIndication();
void sendVideoFocusLost();

VideoSignals::Pointer videoSignals_;

asio::io_service::strand strand_;
aasdk::channel::av::VideoServiceChannel::Pointer channel_;
projection::IVideoOutput::Pointer videoOutput_;
int32_t session_;
sigc::connection focusRequest;
sigc::connection focusRelease;
sigc::connection focusChanged;
};

}
2 changes: 1 addition & 1 deletion include/autoapp/Signals/VideoSignals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ enum class VIDEO_FOCUS_REQUESTOR : uint8_t {
class VideoSignals : public sigc::trackable {
public:
typedef std::shared_ptr<VideoSignals> Pointer;
using type_signal_focus = sigc::signal<void(VIDEO_FOCUS_REQUESTOR)>;
using type_signal_focus = sigc::signal<void(void)>;
type_signal_focus focusRequest;
type_signal_focus focusRelease;
sigc::signal<void(bool)> focusChanged;
Expand Down
33 changes: 12 additions & 21 deletions src/autoapp/Managers/AAPA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ uint8_t AADBus::GetAvailable() {

void AADBus::VideoProjectionEventToMD(uint32_t videoProjectionEvent) {
LOG(DEBUG) << "VideoProjectionEventToMD " << videoProjectionEvent;
if (videoProjectionEvent == 0) {
vs->focusChanged.emit(true);
} else {
if (videoProjectionEvent == 1) {
vs->focusChanged.emit(false);
}
if (videoProjectionEvent == 4){
vs->focusChanged.emit(true);
}
}

AADBus::NowPlayingInfo AADBus::GetNowPlayingInfo() {
Expand Down Expand Up @@ -55,7 +56,6 @@ AAPA::AAPA(VideoSignals::Pointer videosignals, AASignals::Pointer aasignals,

releaseFocusConnection = vs->focusRelease.connect(sigc::mem_fun(*this, &AAPA::releaseFocus));
requestFocusConnection = vs->focusRequest.connect(sigc::mem_fun(*this, &AAPA::requestFocus));
FocusChangeConnection = vs->focusChanged.connect(sigc::mem_fun(*this, &AAPA::FocusChange));
ConnectedConnection = as->connected.connect(sigc::mem_fun(*this, &AAPA::AAConnected));


Expand All @@ -65,41 +65,32 @@ AAPA::AAPA(VideoSignals::Pointer videosignals, AASignals::Pointer aasignals,
}

void AAPA::DisplayMode(uint32_t DisplayMode) {
// currentDisplayMode != 0 means backup camera wants the screen
// currentDisplayMode != 0 means backup camera wants the screen
if ((bool) DisplayMode && _connected) {
this->vs->focusRelease.emit(VIDEO_FOCUS_REQUESTOR::BACKUP_CAMERA);
if (hasFocus) {
this->waitsForFocus = true;
}
} else {
if (waitsForFocus) {
this->vs->focusRequest.emit(VIDEO_FOCUS_REQUESTOR::BACKUP_CAMERA);
waitsForFocus = false;
}
vs->focusChanged.emit(false);
}
}

void AAPA::FocusChange(bool focus) {
hasFocus = focus;
}

void AAPA::requestFocus(VIDEO_FOCUS_REQUESTOR requestor) {
void AAPA::requestFocus() {
adapter->signal_VideoProjectionRequestFromMD()->emit(0);
adapter->signal_ProjectionStatusResult()->emit(true);
vs->focusChanged.emit(true);
}

void AAPA::releaseFocus(VIDEO_FOCUS_REQUESTOR requestor) {
void AAPA::releaseFocus() {
adapter->signal_VideoProjectionRequestFromMD()->emit(1);
vs->focusChanged.emit(false);
}

AAPA::~AAPA() {
LOG(DEBUG) << "Stopping VideoManager";
releaseFocusConnection.disconnect();
requestFocusConnection.disconnect();
FocusChangeConnection.disconnect();
releaseFocus(VIDEO_FOCUS_REQUESTOR::HEADUNIT);
ConnectedConnection.disconnect();
releaseFocus();
}
void AAPA::AAConnected(bool connected) {
LOG(DEBUG) << "AAConnected" << connected;
_connected = connected;
}
2 changes: 1 addition & 1 deletion src/autoapp/Managers/HttpManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ HttpManager::HttpManager(VideoSignals::Pointer videosignals, AASignals::Pointer

response->write(SimpleWeb::StatusCode::success_ok, header);

videosignals_->focusRequest.emit(VIDEO_FOCUS_REQUESTOR::HEADUNIT);
videosignals_->focusRequest.emit();

LOG(DEBUG) << "Got /takeVideoFocus call.";
};
Expand Down
20 changes: 9 additions & 11 deletions src/autoapp/Managers/VideoManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,35 @@ void VideoManager::DisplayMode(uint32_t DisplayMode) {
this->currentDisplayMode = (bool) DisplayMode;
// currentDisplayMode != 0 means backup camera wants the screen
if ((bool) DisplayMode) {
this->vs->focusRelease.emit(VIDEO_FOCUS_REQUESTOR::BACKUP_CAMERA);
this->vs->focusRelease.emit();
if (hasFocus) {
this->waitsForFocus = true;
}
} else {
this->vs->focusRequest.emit(VIDEO_FOCUS_REQUESTOR::BACKUP_CAMERA);
this->vs->focusRequest.emit();
}
}

void VideoManager::requestFocus(VIDEO_FOCUS_REQUESTOR requestor) {
if (currentDisplayMode && requestor == VIDEO_FOCUS_REQUESTOR::ANDROID_AUTO) {
void VideoManager::requestFocus() {
if (currentDisplayMode) {
// we can safely exit - backup camera will notice us when we finish and we request focus back
waitsForFocus = true;
return;
}
if (waitsForFocus && requestor == VIDEO_FOCUS_REQUESTOR::BACKUP_CAMERA) {
if (waitsForFocus) {
// need to wait for a second (maybe less but 100ms is too early) to make sure
// the CMU has already changed the surface from backup camera to opera
sleep(1);
waitsForFocus = false;
}
LOG(DEBUG) << "Setting focus, requested by "
<< static_cast<std::underlying_type<VIDEO_FOCUS_REQUESTOR>::type>(requestor);
LOG(DEBUG) << "Setting focus";
hasFocus = true;
gui->getcom_jci_nativeguictrlInterface()->SetRequiredSurfaces(std::to_string(SURFACES::TV_TOUCH_SURFACE), 1);
vs->focusChanged.emit(true);
}

void VideoManager::releaseFocus(VIDEO_FOCUS_REQUESTOR requestor) {
LOG(DEBUG) << "Releasing focus, requested by "
<< static_cast<std::underlying_type<VIDEO_FOCUS_REQUESTOR>::type>(requestor);
void VideoManager::releaseFocus() {
LOG(DEBUG) << "Releasing focus";
hasFocus = false;
gui->getcom_jci_nativeguictrlInterface()->SetRequiredSurfaces(std::to_string(SURFACES::JCI_OPERA_PRIMARY), 1);
vs->focusChanged.emit(false);
Expand All @@ -61,6 +59,6 @@ VideoManager::~VideoManager() {
LOG(DEBUG) << "Stopping VideoManager";
releaseFocusConnection.disconnect();
requestFocusConnection.disconnect();
releaseFocus(VIDEO_FOCUS_REQUESTOR::HEADUNIT);
releaseFocus();
bucpsa.reset();
}
5 changes: 3 additions & 2 deletions src/autoapp/Projection/InputDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ void InputDevice::audio_focus(aasdk::messenger::ChannelId channel_id, aasdk::pro
}

void InputDevice::video_focus(bool state) {
LOG(DEBUG) << "video_focus " << state;
videoFocus_ = state;
if (videoFocus_) {
if (keyboard_dev != nullptr) {
Expand Down Expand Up @@ -283,9 +284,9 @@ void InputDevice::handle_key(input_event *ev) {
return;
case ButtonCode::BACK: // We use both these buttons for releasing focus, so fall through to the next case.
case ButtonCode::CALL_END:LOG(DEBUG) << "Release Video Focus";
videosignals_->focusRelease.emit(VIDEO_FOCUS_REQUESTOR::HEADUNIT);
videosignals_->focusRelease.emit();
return;
case ButtonCode::HOME:videosignals_->focusRequest.emit(VIDEO_FOCUS_REQUESTOR::HEADUNIT);
case ButtonCode::HOME:videosignals_->focusRequest.emit();
return;
default:break;
}
Expand Down
37 changes: 13 additions & 24 deletions src/autoapp/Service/VideoService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ void VideoService::start() {
void VideoService::stop() {
strand_.dispatch([this, self = this->shared_from_this()]() {
LOG(INFO) << "[VideoService] stop.";
focusRelease.disconnect();
focusRequest.disconnect();
videoSignals_->focusRelease.emit(VIDEO_FOCUS_REQUESTOR::ANDROID_AUTO);
focusChanged.disconnect();
videoSignals_->focusRelease.emit();
});
}

Expand All @@ -64,8 +63,12 @@ void VideoService::resume() {
void VideoService::onChannelOpenRequest(const aasdk::proto::messages::ChannelOpenRequest &request) {
LOG(INFO) << "[VideoService] open request, priority: " << request.priority();
const aasdk::proto::enums::Status::Enum status = aasdk::proto::enums::Status::OK;
focusRequest = videoSignals_->focusRequest.connect(sigc::mem_fun(*this, &VideoService::sendVideoFocusIndication));
focusRelease = videoSignals_->focusRelease.connect(sigc::mem_fun(*this, &VideoService::sendVideoFocusLost));
focusChanged = videoSignals_->focusChanged.connect([this](bool focus) {
if (focus) {
sendVideoFocusIndication();
}
else { sendVideoFocusLost(); }
});
LOG(INFO) << "[VideoService] open status: " << status;

aasdk::proto::messages::ChannelOpenResponse response;
Expand All @@ -87,7 +90,7 @@ void VideoService::onAVChannelSetupRequest(const aasdk::proto::messages::AVChann
: aasdk::proto::enums::AVChannelSetupStatus::FAIL;
LOG(INFO) << "[VideoService] setup status: " << status;

videoSignals_->focusRequest.emit(VIDEO_FOCUS_REQUESTOR::ANDROID_AUTO);
videoSignals_->focusRequest.emit();

aasdk::proto::messages::AVChannelSetupResponse response;
response.set_media_status(status);
Expand All @@ -96,7 +99,7 @@ void VideoService::onAVChannelSetupRequest(const aasdk::proto::messages::AVChann

auto promise = aasdk::channel::SendPromise::defer(strand_);
promise->then([this, self =
this->shared_from_this()]() -> void { this->sendVideoFocusIndication(VIDEO_FOCUS_REQUESTOR::ANDROID_AUTO); },
this->shared_from_this()]() -> void { this->sendVideoFocusIndication(); },
[this, self =
this->shared_from_this()](const aasdk::error::Error &e) -> void { this->onChannelError(e); });
channel_->sendAVChannelSetupResponse(response, std::move(promise));
Expand Down Expand Up @@ -180,25 +183,11 @@ void VideoService::onVideoFocusRequest(const aasdk::proto::messages::VideoFocusR
<< ", focus mode: " << request.focus_mode()
<< ", focus reason: " << request.focus_reason();

videoSignals_->focusRequest.emit(VIDEO_FOCUS_REQUESTOR::ANDROID_AUTO);

// stop video service on go back to openauto
// if (request.focus_mode() == 2) {
// LOG(INFO) << "[VideoService] Back to CSNG...";
// try {
// if (!std::ifstream("/tmp/entityexit")) {
// std::ofstream("/tmp/entityexit");
// }
// } catch (...) {
// LOG(ERROR) << "[VideoService] Error in creating entityexit";
// }
// }

// this->sendVideoFocusIndication();
videoSignals_->focusRequest.emit();
channel_->receive(this->shared_from_this());
}

void VideoService::sendVideoFocusIndication(__attribute__((unused)) VIDEO_FOCUS_REQUESTOR requestor) {
void VideoService::sendVideoFocusIndication() {
LOG(INFO) << "[VideoService] video focus indication.";

aasdk::proto::messages::VideoFocusIndication videoFocusIndication;
Expand All @@ -212,7 +201,7 @@ void VideoService::sendVideoFocusIndication(__attribute__((unused)) VIDEO_FOCUS_
channel_->sendVideoFocusIndication(videoFocusIndication, std::move(promise));
}

void VideoService::sendVideoFocusLost(__attribute__((unused)) VIDEO_FOCUS_REQUESTOR requestor) {
void VideoService::sendVideoFocusLost() {
LOG(INFO) << "[VideoService] video focus indication.";

aasdk::proto::messages::VideoFocusIndication videoFocusIndication;
Expand Down
2 changes: 1 addition & 1 deletion src/autoapp/autoapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ int main(int argc, char *argv[]) {
}

signals.audioSignals->focusRelease.emit(aasdk::messenger::ChannelId::MEDIA_AUDIO);
signals.videoSignals->focusRelease.emit(VIDEO_FOCUS_REQUESTOR::HEADUNIT);
signals.videoSignals->focusRelease.emit();
sleep(2);
// signals.aaSignals->shutdown.emit();
//
Expand Down

0 comments on commit 9438067

Please sign in to comment.