Skip to content

Commit

Permalink
Create seek method on main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
jcdr428 committed Oct 4, 2023
1 parent 3a8a9aa commit 2539d07
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions tsMuxer/abstractReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class AbstractReader
AbstractReader() : m_blockSize(0), m_allocSize(0), m_prereadThreshold(0) {}
virtual ~AbstractReader() = default;
virtual uint8_t* readBlock(int readerID, uint32_t& readCnt, int& rez, bool* firstBlockVar = nullptr) = 0;
virtual bool seek(int readerID, int64_t offset) = 0;
virtual bool incSeek(int readerID, int64_t offset) = 0;
virtual void notify(int readerID, uint32_t dataReaded) = 0;
virtual int createReader(int readBuffOffset = 0) = 0;
Expand Down
11 changes: 11 additions & 0 deletions tsMuxer/bufferedReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ ReaderData* BufferedReader::getReader(const int readerID)
return itr != m_readers.end() ? itr->second : nullptr;
}

bool BufferedReader::seek(const int readerID, const int64_t offset)
{
const auto itr = m_readers.find(readerID);
if (itr != m_readers.end())
{
ReaderData* data = itr->second;
return data->incSeek(offset);
}
return false;
}

bool BufferedReader::incSeek(const int readerID, const int64_t offset)
{
std::lock_guard lock(m_readersMtx);
Expand Down
1 change: 1 addition & 0 deletions tsMuxer/bufferedReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class BufferedReader : public AbstractReader, TerminatableThread
uint32_t getReaderCount();
void terminate();
void setFileIterator(FileNameIterator* itr, int readerID);
bool seek(int readerID, int64_t offset) override;
bool incSeek(int readerID, int64_t offset) override;
bool gotoByte(int readerID, int64_t seekDist) override { return false; }

Expand Down
3 changes: 1 addition & 2 deletions tsMuxer/ioContextDemuxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ void IOContextDemuxer::skip_bytes(const int64_t size)
if (skipLeft > 2LL * m_fileBlockSize)
{
const int64_t offset = skipLeft - 2LL * m_fileBlockSize;
m_bufferedReader->incSeek(m_readerID, offset);
this_thread::sleep_for(1s);
m_bufferedReader->seek(m_readerID, offset);
m_processedBytes += offset;
skipLeft = 2LL * m_fileBlockSize;
}
Expand Down
1 change: 1 addition & 0 deletions tsMuxer/metaDemuxer.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class ContainerToReaderWrapper final : public AbstractReader
m_terminated = false;
}
uint8_t* readBlock(int readerID, uint32_t& readCnt, int& rez, bool* firstBlockVar = nullptr) override;
bool seek(int readerID, int64_t offset) override { return false; }
bool incSeek(int readerID, int64_t offset) override { return false; }
void notify(int readerID, uint32_t dataReaded) override {}
int createReader(int readBuffOffset = 0) override;
Expand Down

0 comments on commit 2539d07

Please sign in to comment.