Skip to content

Commit

Permalink
Implement SPS Frame parser to get fps before first packet is send
Browse files Browse the repository at this point in the history
  • Loading branch information
peak3d committed Aug 11, 2017
1 parent 546b7f2 commit a98e877
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 15 deletions.
30 changes: 26 additions & 4 deletions lib/libbento4/Codecs/Ap4AvcParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -945,15 +945,37 @@ AP4_AvcFrameParser::AppendNalUnitData(const unsigned char* data, unsigned int da
m_AccessUnitData.Append(new AP4_DataBuffer(data, data_size));
}

/*----------------------------------------------------------------------
| AP4_AvcFrameParser::Feed
+---------------------------------------------------------------------*/
AP4_Result AP4_AvcFrameParser::ParseFrameForSPS(const AP4_Byte* data, AP4_Size data_size, AP4_UI08 naluLengthSize, AP4_AvcSequenceParameterSet &sps)
{
if (data_size < naluLengthSize)
return AP4_ERROR_EOS;

while (data_size > naluLengthSize)
{
AP4_Size nalSize(0);
for (unsigned int i(0); i < naluLengthSize; ++i) { nalSize = (nalSize << 8) + *data++; };
data_size -= naluLengthSize;
if (nalSize > data_size)
return AP4_ERROR_INVALID_PARAMETERS;

if ((*data & 0x1F) == AP4_AVC_NAL_UNIT_TYPE_SPS)
return ParseSPS(data, data_size, sps);
data_size -= nalSize;
}
}

/*----------------------------------------------------------------------
| AP4_AvcFrameParser::Feed
+---------------------------------------------------------------------*/
AP4_Result
AP4_AvcFrameParser::Feed(const void* data,
AP4_Size data_size,
AP4_Size& bytes_consumed,
AccessUnitInfo& access_unit_info,
bool eos)
AP4_Size data_size,
AP4_Size& bytes_consumed,
AccessUnitInfo& access_unit_info,
bool eos)
{
const AP4_DataBuffer* nal_unit = NULL;

Expand Down
13 changes: 9 additions & 4 deletions lib/libbento4/Codecs/Ap4AvcParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ class AP4_AvcFrameParser {
AP4_AvcFrameParser();
~AP4_AvcFrameParser();

static AP4_Result AP4_AvcFrameParser::ParseFrameForSPS(const AP4_Byte* data,
AP4_Size data_size,
AP4_UI08 naluLengthSize,
AP4_AvcSequenceParameterSet &sps);

/**
* Feed some data to the parser and look for the next NAL Unit.
*
Expand Down Expand Up @@ -257,10 +262,10 @@ class AP4_AvcFrameParser {
* responsible for freeing this data by calling AccessUnitInfo::Reset()
*/
AP4_Result Feed(const void* data,
AP4_Size data_size,
AP4_Size& bytes_consumed,
AccessUnitInfo& access_unit_info,
bool eos=false);
AP4_Size data_size,
AP4_Size& bytes_consumed,
AccessUnitInfo& access_unit_info,
bool eos=false);

AP4_AvcSequenceParameterSet** GetSequenceParameterSets() { return &m_SPS[0]; }
AP4_AvcPictureParameterSet** GetPictureParameterSets() { return &m_PPS[0]; }
Expand Down
17 changes: 10 additions & 7 deletions src/common/AdaptiveStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ bool AdaptiveStream::write_data(const void *buffer, size_t buffer_size)
{
std::lock_guard<std::mutex> lckrw(thread_data_->mutex_rw_);

if (stopped_)
return false;

size_t insertPos(segment_buffer_.size());
segment_buffer_.resize(insertPos + buffer_size);
tree_.OnDataArrived(const_cast<AdaptiveTree::Representation*>(current_rep_), current_seg_,
Expand Down Expand Up @@ -293,17 +296,17 @@ uint32_t AdaptiveStream::read(void* buffer, uint32_t bytesToRead)
continue;
}

if (avail >= bytesToRead)
{
if (avail > bytesToRead)
avail = bytesToRead;
if (avail > bytesToRead)
avail = bytesToRead;

memcpy(buffer, segment_buffer_.data() + segment_read_pos_, avail);
segment_read_pos_ += avail;
absolute_position_ += avail;

if (avail == bytesToRead)
{
memcpy(buffer, segment_buffer_.data() + (segment_read_pos_ - avail), avail);
return avail;
}
segment_read_pos_ += avail;
absolute_position_ += avail;
return 0;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/common/AdaptiveStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <thread>
#include <mutex>
#include <condition_variable>

namespace adaptive
{
Expand Down
3 changes: 3 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,9 @@ class FragmentedSampleReader : public SampleReader, public AP4_LinearReader
return result;
}

//AP4_AvcSequenceParameterSet sps;
//AP4_AvcFrameParser::ParseFrameForSPS(m_sampleData.GetData(), m_sampleData.GetDataSize(), 4, sps);

//Protection could have changed in ProcessMoof
if (!decrypterPresent && m_decrypter != nullptr && !useDecryptingDecoder)
m_encrypted.SetData(m_sampleData.GetData(), m_sampleData.GetDataSize());
Expand Down

0 comments on commit a98e877

Please sign in to comment.