Skip to content

Commit

Permalink
- Fix for 'ipco' and 'iprp' boxes. They are changed from FullBox to B…
Browse files Browse the repository at this point in the history
…ox to be aligned with latest spec as of Feb. 2016.

- Add support for reading Conding constraints Box (ccst) entried from JSON configuration.
- Make tkhd alternate_group writing optional from JSON configuration.
- ItemInfoEntry writing fixed to be written always in ID order.
- HevcSampleEntry 'ccst' is now not written for video tracks (i.e. 'vide' track).
- Fix for SampleToChunkBox::decodeEntries to handle last entry correctly when multiple same sample entries per chunk in last entry.
- Add support for writing hidden master images.
- Support largesize field in subboxes.
- Support reading 64-bit box sizes.
- Fix Sample Size Box reading.
- Add reader support for multiple sample chunks.
- Add support for 64-bit Chunk Offset Box "co64".
  • Loading branch information
nokiatech committed Feb 24, 2016
1 parent c151adf commit 30d7109
Show file tree
Hide file tree
Showing 65 changed files with 802 additions and 468 deletions.
8 changes: 7 additions & 1 deletion Srcs/common/bitstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,15 @@ int BitStream::readSignedExpGolombCode()

BitStream BitStream::readSubBoxBitStream(std::string& boxType)
{
const uint32_t boxSize = read32Bits();
uint64_t boxSize = read32Bits();
readStringWithLen(boxType, 4);

if (boxSize == 1) // Check if 'largesize' field is used
{
boxSize = read64Bits();
mByteOffset -= 8;
}

mByteOffset -= 8;

BitStream subBitstr;
Expand Down
1 change: 1 addition & 0 deletions Srcs/common/bitstream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#ifndef BITSTREAM_HPP
#define BITSTREAM_HPP

#include <cstdint>
#include <string>
#include <vector>

Expand Down
60 changes: 40 additions & 20 deletions Srcs/common/chunkoffsetbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,29 @@

#include "chunkoffsetbox.hpp"
#include "bitstream.hpp"
#include <algorithm>
#include <limits>

ChunkOffsetBox::ChunkOffsetBox() :
FullBox("stco", 0, 0),
mEntryCount(0),
mChunkOffsets()
{
}

void ChunkOffsetBox::setEntryCount(uint32_t entry_count)
void ChunkOffsetBox::setChunkOffsets(const std::vector<uint64_t>& chunkOffsets)
{
mEntryCount = entry_count;
}

uint32_t ChunkOffsetBox::getEntryCount()
{
return mEntryCount;
}

void ChunkOffsetBox::setChunkOffsets(const std::vector<uint32_t>& chunk_offsets)
{
mChunkOffsets = chunk_offsets;
mChunkOffsets = chunkOffsets;
if (*std::max_element(mChunkOffsets.cbegin(), mChunkOffsets.cend()) > std::numeric_limits<std::uint32_t>::max())
{
setType("co64");
}
else
{
setType("stco");
}
}

std::vector<uint32_t> ChunkOffsetBox::getChunkOffsets()
std::vector<uint64_t> ChunkOffsetBox::getChunkOffsets()
{
return mChunkOffsets;
}
Expand All @@ -45,10 +44,21 @@ void ChunkOffsetBox::writeBox(BitStream& bitstr)
// Write box headers
writeFullBoxHeader(bitstr);

bitstr.write32Bits(mEntryCount);
for (uint32_t i = 0; i < mEntryCount; i++)
bitstr.write32Bits(mChunkOffsets.size());
if (getType() == "stco")
{
bitstr.write32Bits(mChunkOffsets.at(i));
for (uint32_t i = 0; i < mChunkOffsets.size(); ++i)
{
bitstr.write32Bits(mChunkOffsets.at(i));
}
}
else
{
// This is a ChunkLargeOffsetBox 'co64' with unsigned int (64) chunk_offsets.
for (uint32_t i = 0; i < mChunkOffsets.size(); ++i)
{
bitstr.write64Bits(mChunkOffsets.at(i));
}
}

// Update the size of the movie box
Expand All @@ -62,9 +72,19 @@ void ChunkOffsetBox::parseBox(BitStream& bitstr)
// First parse the box header
parseFullBoxHeader(bitstr);

mEntryCount = bitstr.read32Bits();
for (uint32_t i = 0; i < mEntryCount; i++)
const std::uint32_t entryCount = bitstr.read32Bits();
if (getType() == "stco")
{
for (uint32_t i = 0; i < entryCount; ++i)
{
mChunkOffsets.push_back(bitstr.read32Bits());
}
}
else // This is a ChunkLargeOffsetBox 'co64' with unsigned int (64) chunk_offsets.
{
mChunkOffsets.push_back(bitstr.read32Bits());
for (uint32_t i = 0; i < entryCount; ++i)
{
mChunkOffsets.push_back(bitstr.read64Bits());
}
}
}
27 changes: 8 additions & 19 deletions Srcs/common/chunkoffsetbox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
#define CHUNKOFFSETBOX_HPP

#include "fullbox.hpp"
#include <string>

class BitStream;

/** @brief Chunk Offset Box class
* @details 'stco' box implementation. Extends from FullBox.
/** @brief Chunk Offset Box and Large Chunk Offset Box class
* @details 'stco' and 'co64' box implementation. Extends from FullBox.
*/

class ChunkOffsetBox : public FullBox
Expand All @@ -28,19 +27,12 @@ class ChunkOffsetBox : public FullBox
ChunkOffsetBox();
virtual ~ChunkOffsetBox() = default;

/** @brief Sets the number of entries in the chunk offset box
* @param [in] entry_count number of entries */
void setEntryCount(std::uint32_t entry_count);

///@return Number of entries in the Chunk Offset Box
uint32_t getEntryCount();

/** @brief Sets the chunk offset values
/** @brief Sets the chunk offset values. If some of values does not fit 32-bit field, the box type is set to 'co64'.
* @param [in] chunk_offsets Chunk offset values */
void setChunkOffsets(const std::vector<std::uint32_t>& chunk_offsets);
void setChunkOffsets(const std::vector<std::uint64_t>& chunkOffsets);

///@return Chunk offset values as a vector of unsigned 32 bit integers
std::vector<std::uint32_t> getChunkOffsets();
/// @return Chunk offset values as a vector.
std::vector<std::uint64_t> getChunkOffsets();

/** @brief Creates the bitstream that represents the box in the ISOBMFF file
* @param [out] bitstr Bitstream that contains the box data */
Expand All @@ -51,11 +43,8 @@ class ChunkOffsetBox : public FullBox
virtual void parseBox(BitStream& bitstr);

private:
///@brief number of entries in the chunk offset box
std::uint32_t mEntryCount;

///@brief vector of chunk offset values as unsigned 32 bit integers
std::vector<std::uint32_t> mChunkOffsets;
/// @brief Chunk offset values. 'stco' uses just first 32 bits, 'co64' all 64 bits.
std::vector<std::uint64_t> mChunkOffsets;
};

#endif /* end of include guard: CHUNKOFFSETBOX_HPP */
Expand Down
15 changes: 8 additions & 7 deletions Srcs/common/hevcsampleentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,26 @@ HevcConfigurationBox& HevcSampleEntry::getHevcConfigurationBox()
return mHevcConfigurationBox;
}

CodingConstraintsBox& HevcSampleEntry::getCodingConstraintsBox()
void HevcSampleEntry::createCodingConstraintsBox()
{
return mCodingConstraintsBox;
mIsCodingConstraintsPresent = true;
}


bool HevcSampleEntry::isCodingConstraintsBoxPresent() const
CodingConstraintsBox* HevcSampleEntry::getCodingConstraintsBox()
{
return mIsCodingConstraintsPresent;
return (mIsCodingConstraintsPresent ? &mCodingConstraintsBox : nullptr);
}


void HevcSampleEntry::writeBox(BitStream& bitstr)
{
VisualSampleEntryBox::writeBox(bitstr);

mHevcConfigurationBox.writeBox(bitstr);

mCodingConstraintsBox.writeBox(bitstr);
if (mIsCodingConstraintsPresent)
{
mCodingConstraintsBox.writeBox(bitstr);
}

// Update the size of the movie box
updateSize(bitstr);
Expand Down
11 changes: 5 additions & 6 deletions Srcs/common/hevcsampleentry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@ class HevcSampleEntry : public VisualSampleEntryBox
* @return Reference to the HevcConfigurationBox **/
HevcConfigurationBox& getHevcConfigurationBox();

/** @brief Gets the CodingConstraintsBox
* @return Reference to the CodingConstraintsBox **/
CodingConstraintsBox& getCodingConstraintsBox();
/** @brief Create CodingConstraintsBox */
void createCodingConstraintsBox();

/** @brief Check if CodingConstraintsBox is present
* @return TRUE if CodingConstraintsBox is present, FALSE otherwise **/
bool isCodingConstraintsBoxPresent() const;
/** @brief Gets the CodingConstraintsBox
* @return Pointer to CodingConstraintsBox, if present. */
virtual CodingConstraintsBox* getCodingConstraintsBox() override;

/** @brief Creates the bitstream that represents the box in the ISOBMFF file
* @param [out] bitstr Bitstream that contains the box data. */
Expand Down
Loading

0 comments on commit 30d7109

Please sign in to comment.