<commit_before>// -*-c++-*-
// Copyright (c) 2017 <NAME>.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#include <glog/logging.h>

#include "RtspWanClient.h"
#include "DescribeResponse.h"
#include "SetupResponse.h"

#include "H264Depacketizer.h"


Overflow::RtspWanClient::RtspWanClient(Overflow::IRtspDelegate * const delegate, const std::string& url)
    : m_url(url),
      m_loop(),
      m_keep_alive_timer(m_loop),
      m_rtsp_timeout_milliseconds(1000),
      m_thread(nullptr),
      m_delegate(delegate),
      m_transport(this, m_loop, url),
      m_factory(url),
      m_palette(),
      m_keepAliveIntervalInSeconds(60),
      m_session(),
      m_processedFirstPayload(false) { }

Overflow::RtspWanClient::~RtspWanClient()
{
    Stop();
}

bool Overflow::RtspWanClient::SendDescribeRequest()
{
    Describe* describe_request = m_factory.DescribeRequest();

    Response *resp = nullptr;
    bool received = SendRtsp(describe_request, resp);

    if (received == false) {
        delete describe_request;
        return false;
    }
    
    const DescribeResponse rtsp_resp(resp);
    const std::vector<SessionDescription>& palettes = rtsp_resp.GetSessionDescriptions();

    
    bool ok = rtsp_resp.Ok();
    if (ok) {
        m_palette = AskDelegateForPalette(palettes);
    }

    delete describe_request;
    delete resp;

    return ok;
}

bool Overflow::RtspWanClient::SendSetupRequest(bool serverAllowsAggregate)
{   
    // control url is where we put any more requests to
    std::string setup_url = (m_palette.IsControlUrlComplete()) ?
        m_palette.GetControl() :
        m_factory.GetPath() + "/" + m_palette.GetControl();

    LOG(INFO) << "SETUP URL: " << setup_url;
    <commit_msg>log timeout describe and cleanup formatting<commit_after>// -*-c++-*-
// Copyright (c) 2017 <NAME>.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#include <glog/logging.h>

#include "RtspWanClient.h"
#include "DescribeResponse.h"
#include "SetupResponse.h"

#include "H264Depacketizer.h"


Overflow::RtspWanClient::RtspWanClient(Overflow::IRtspDelegate * const delegate, const std::string& url)
    : m_url(url),
      m_loop(),
      m_keep_alive_timer(m_loop),
      m_rtsp_timeout_milliseconds(1000),
      m_thread(nullptr),
      m_delegate(delegate),
      m_transport(this, m_loop, url),
      m_factory(url),
      m_palette(),
      m_keepAliveIntervalInSeconds(60),
      m_session(),
      m_processedFirstPayload(false) { }

Overflow::RtspWanClient::~RtspWanClient()
{
    Stop();
}

bool Overflow::RtspWanClient::SendDescribeRequest()
{
    Describe* describe_request = m_factory.DescribeRequest();

    Response *resp = nullptr;
    bool received = SendRtsp(describe_request, resp);

    if (received == false) {
        LOG(ERROR) << "describe request timeout";
        delete describe_request;
        return false;
    }
    
    const DescribeResponse rtsp_resp(resp);
    bool ok = rtsp_resp.Ok();
    
    if (ok) {
        const std::vector<SessionDescription>& palettes = rtsp_resp.GetSessionDescriptions();
        m_palette = AskDelegateForPalette(palettes);
    }

    delete describe_request;
    delete resp;

    return ok;
}

bool Overflow::RtspWanClient::SendSetupRequest(bool serverAllowsAggregate)
{   
    // control url is where we put any more requests to
    std::string setup_url = (m_palette.IsControlUrlComplete()) ?
        m_palette.GetControl() :
        m_factory.GetPath() + "/" + m_palette.GetControl();

    LOG(INFO) << "SETUP URL: " << setup_url;
    
{'fraction_non_alphanumeric': 0.1009865470852018, 'fraction_numerical': 0.004663677130044843, 'mean_word_length': 3.6778523489932886, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7180460', 'n_tokens_mistral': 1671, 'n_tokens_neox': 1613, 'n_words': 533}