Commit e0ac707d authored by Tristan Matthews's avatar Tristan Matthews
Browse files

* #14077: sdp/video: less hackish way of parsing SDP

parent 45753959
......@@ -478,60 +478,39 @@ string Sdp::getLineFromSession(const pjmedia_sdp_session *sess, const string &ke
// SDP and deal with the streams properly at that level
string Sdp::getIncomingVideoDescription() const
{
stringstream ss;
ss << "v=0" << std::endl;
ss << "o=- 0 0 IN IP4 " << localIpAddr_ << std::endl;
ss << "s=" << PACKAGE_NAME << std::endl;
ss << "c=IN IP4 " << remoteIpAddr_ << std::endl;
ss << "t=0 0" << std::endl;
std::string videoLine(getLineFromSession(activeLocalSession_, "m=video"));
ss << videoLine << std::endl;
int payload_num;
if (sscanf(videoLine.c_str(), "m=video %*d %*s %d", &payload_num) != 1)
payload_num = 0;
std::ostringstream s;
s << "a=rtpmap:";
s << payload_num;
std::string vCodecLine(getLineFromSession(activeLocalSession_, s.str()));
ss << vCodecLine << std::endl;
std::string profileLevelID;
getProfileLevelID(activeLocalSession_, profileLevelID, payload_num);
if (not profileLevelID.empty())
ss << "a=fmtp:" << payload_num << " " << profileLevelID << std::endl;
pjmedia_sdp_session *videoSession = pjmedia_sdp_session_clone(memPool_, activeLocalSession_);
if (!videoSession) {
ERROR("Could not clone SDP");
return "";
}
unsigned videoIdx = 0;
while (videoIdx < activeLocalSession_->media_count and
pj_stricmp2(&activeLocalSession_->media[videoIdx]->desc.media, "video") != 0)
++videoIdx;
// deactivate non-video media
bool hasVideo = false;
for (unsigned i = 0; i < videoSession->media_count; i++)
if (pj_stricmp2(&videoSession->media[i]->desc.media, "video")) {
if (pjmedia_sdp_media_deactivate(memPool_, videoSession->media[i]) != PJ_SUCCESS)
ERROR("Could not deactivate media");
} else {
hasVideo = true;
}
if (videoIdx == activeLocalSession_->media_count) {
DEBUG("No video present in local session");
if (not hasVideo) {
DEBUG("No video present in active local SDP");
return "";
}
// get direction string
static const pj_str_t DIRECTIONS[] = {
{(char*) "sendrecv", 8},
{(char*) "sendonly", 8},
{(char*) "recvonly", 8},
{(char*) "inactive", 8},
{NULL, 0}
};
pjmedia_sdp_attr *direction = NULL;
char buffer[4096];
size_t size = pjmedia_sdp_print(videoSession, buffer, sizeof(buffer));
string sessionStr(buffer, std::min(size, sizeof(buffer)));
const pj_str_t *guess = DIRECTIONS;
while (!direction and guess->ptr)
direction = pjmedia_sdp_media_find_attr(activeLocalSession_->media[videoIdx], guess++, NULL);
// FIXME: find a way to get rid of the "m=audio..." line with PJSIP
if (direction)
ss << "a=" + std::string(direction->name.ptr, direction->name.slen) << std::endl;
const size_t audioPos = sessionStr.find("m=audio");
const size_t newline2 = sessionStr.find('\n', audioPos);
const size_t newline1 = sessionStr.rfind('\n', audioPos);
return ss.str();
sessionStr.erase(newline1, newline2 - newline1);
return sessionStr;
}
std::string Sdp::getOutgoingVideoCodec() const
......
......@@ -147,13 +147,12 @@ void VideoReceiveThread::setup()
av_dict_set(&options, "channel", args_["channel"].c_str(), 0);
// Open video file
DEBUG("Opening input");
inputCtx_ = avformat_alloc_context();
inputCtx_->interrupt_callback = interruptCb_;
int ret = avformat_open_input(&inputCtx_, input.c_str(), file_iformat, options ? &options : NULL);
EXIT_IF_FAIL(ret == 0, "Could not open input \"%s\"", input.c_str());
if (not sdpFilename_.empty() and remove(sdpFilename_.c_str()) != 0)
ERROR("Could not remove %s", sdpFilename_.c_str());
EXIT_IF_FAIL(ret == 0, "Could not open input \"%s\"", input.c_str());
DEBUG("Finding stream info");
if (requestKeyFrameCallback_)
......@@ -167,7 +166,6 @@ void VideoReceiveThread::setup()
EXIT_IF_FAIL(ret >= 0, "Could not find stream info!");
// find the first video stream from the input
streamIndex_ = -1;
for (size_t i = 0; streamIndex_ == -1 && i < inputCtx_->nb_streams; ++i)
if (inputCtx_->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
streamIndex_ = i;
......@@ -309,7 +307,7 @@ VideoReceiveThread::~VideoReceiveThread()
if (decoderCtx_)
avcodec_close(decoderCtx_);
if (inputCtx_) {
if (streamIndex_ != -1 and inputCtx_) {
#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(53, 8, 0)
av_close_input_file(inputCtx_);
#else
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment