Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

implement sink IDRRequest handling #150

Open
wants to merge 1 commit 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: 2 additions & 0 deletions libwds/public/media_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ class SinkMediaManager : public MediaManager {
* @return connector type. @see ConnectorType
*/
virtual ConnectorType GetConnectorType() const = 0;

virtual void IDRRequestDone(bool success) = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

pls provide description for the newly added method

};

/**
Expand Down
2 changes: 2 additions & 0 deletions libwds/public/sink.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class Sink : public Peer {
* @return newly created Sink instance
*/
static Sink* Create(Peer::Delegate* delegate, SinkMediaManager* mng);

virtual bool IDRRequest() = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

};

}
Expand Down
16 changes: 16 additions & 0 deletions libwds/sink/sink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "libwds/rtsp/play.h"
#include "libwds/rtsp/teardown.h"
#include "libwds/rtsp/triggermethod.h"
#include "libwds/rtsp/idrrequest.h"
#include "libwds/rtsp/setparameter.h"
#include "libwds/public/media_manager.h"
#include "libwds/sink/cap_negotiation_state.h"
#include "libwds/sink/init_state.h"
Expand Down Expand Up @@ -109,6 +111,7 @@ class SinkImpl final : public Sink, public RTSPInputHandler, public MessageHandl
bool Teardown() override;
bool Play() override;
bool Pause() override;
bool IDRRequest() override;

// RTSPInputHandler
void MessageParsed(std::unique_ptr<Message> message) override;
Expand Down Expand Up @@ -180,6 +183,19 @@ bool SinkImpl::Pause() {
return HandleCommand(CreateCommand<rtsp::Pause, Request::M9>());
}

bool SinkImpl::IDRRequest() {
auto request = new rtsp::SetParameter(manager_->GetPresentationUrl());
request->header().set_session(manager_->GetSessionId());
request->header().set_cseq(state_machine_->GetNextCSeq());

auto request_payload = new rtsp::PropertyMapPayload();
request_payload->AddProperty(std::shared_ptr<rtsp::Property>(new rtsp::IDRRequest()));
request->set_payload(std::unique_ptr<rtsp::Payload>(request_payload));

request->set_id(Request::M13);
return HandleCommand(std::unique_ptr<Message>(request));
}

void SinkImpl::MessageParsed(std::unique_ptr<Message> message) {
if (message->is_request() && !InitializeRequestId(ToRequest(message.get()))) {
WDS_ERROR("Cannot identify the received message");
Expand Down
16 changes: 15 additions & 1 deletion libwds/sink/streaming_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,19 @@ class M9SenderOptional final : public OptionalMessageSender<Request::M9> {
}
};

class M13SenderOptional final : public OptionalMessageSender<Request::M13> {
public:
M13SenderOptional(const InitParams& init_params)
: OptionalMessageSender<Request::M13>(init_params) {
}
private:
bool HandleReply(Reply* reply) override {
bool ok = reply->response_code() == rtsp::STATUS_OK;
ToSinkMediaManager(manager_)->IDRRequestDone(ok);
return ok;
}
};

StreamingState::StreamingState(const InitParams& init_params, MessageHandlerPtr m16_handler)
: MessageSequenceWithOptionalSetHandler(init_params) {
AddSequencedHandler(make_ptr(new TeardownHandler(init_params)));
Expand All @@ -219,10 +232,11 @@ StreamingState::StreamingState(const InitParams& init_params, MessageHandlerPtr
AddOptionalHandler(make_ptr(new M3Handler(init_params)));
AddOptionalHandler(make_ptr(new M4Handler(init_params)));

// optional senders that handle sending play, pause and teardown
// optional senders that handle sending play, pause, teardown and idr-request
AddOptionalHandler(make_ptr(new M7SenderOptional(init_params)));
AddOptionalHandler(make_ptr(new M8SenderOptional(init_params)));
AddOptionalHandler(make_ptr(new M9SenderOptional(init_params)));
AddOptionalHandler(make_ptr(new M13SenderOptional(init_params)));
AddOptionalHandler(m16_handler);
}

Expand Down
3 changes: 3 additions & 0 deletions sink/gst_sink_media_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,6 @@ bool GstSinkMediaManager::SetOptimalVideoFormat(const wds::H264VideoFormat& opti
wds::ConnectorType GstSinkMediaManager::GetConnectorType() const {
return wds::ConnectorTypeNone;
}

void GstSinkMediaManager::IDRRequestDone(bool success) {
}
1 change: 1 addition & 0 deletions sink/gst_sink_media_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class GstSinkMediaManager : public wds::SinkMediaManager {
wds::NativeVideoFormat GetNativeVideoFormat() const override;
bool SetOptimalVideoFormat(const wds::H264VideoFormat& optimal_format) override;
wds::ConnectorType GetConnectorType() const override;
void IDRRequestDone(bool success) override;

private:
std::string hostname_;
Expand Down