Skip to content

mediaProperty: check access #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 3, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/AvTranscoder/file/OutputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ bool OutputFile::endWrap( )
return true;
}

void OutputFile::addMetadata( const MetadatasMap& dataMap )
void OutputFile::addMetadata( const PropertiesMap& dataMap )
{
for( MetadatasMap::const_iterator it = dataMap.begin(); it != dataMap.end(); ++it )
for( PropertiesMap::const_iterator it = dataMap.begin(); it != dataMap.end(); ++it )
{
addMetadata( it->first, it->second );
}
Expand Down
2 changes: 1 addition & 1 deletion src/AvTranscoder/file/OutputFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class AvExport OutputFile
* @brief Add metadata to the output file.
* @note Depending on the format, you are not sure to find your metadata after the transcode.
*/
virtual void addMetadata( const MetadatasMap& dataMap );
virtual void addMetadata( const PropertiesMap& dataMap );
virtual void addMetadata( const std::string& key, const std::string& value );

virtual void setVerbose( bool verbose = false ){ _verbose = verbose; }
Expand Down
4 changes: 2 additions & 2 deletions src/AvTranscoder/mediaProperty/AttachementProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ AttachementProperties::AttachementProperties( const AVFormatContext* formatConte
detail::fillMetadataDictionnary( _formatContext->streams[index]->metadata, _metadatas );
}

MetadatasMap AttachementProperties::getDataMap() const
PropertiesMap AttachementProperties::getPropertiesAsMap() const
{
MetadatasMap dataMap;
PropertiesMap dataMap;

detail::add( dataMap, "streamId", _streamId );

Expand Down
8 changes: 5 additions & 3 deletions src/AvTranscoder/mediaProperty/AttachementProperties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,19 @@ class AvExport AttachementProperties
AttachementProperties( const AVFormatContext* formatContext, const size_t index );

size_t getStreamId() const { return _streamId; }
MetadatasMap& getMetadatas() { return _metadatas; }
PropertiesMap& getMetadatas() { return _metadatas; }

#ifndef SWIG
const AVFormatContext& getAVFormatContext() { return *_formatContext; }
#endif

MetadatasMap getDataMap() const;
PropertiesMap getPropertiesAsMap() const; ///< Return all attachement properties as a map (name of property: value)

private:
const AVFormatContext* _formatContext; ///< Has link (no ownership)

size_t _streamId;
MetadatasMap _metadatas;
PropertiesMap _metadatas;
};

}
Expand Down
34 changes: 32 additions & 2 deletions src/AvTranscoder/mediaProperty/AudioProperties.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "AudioProperties.hpp"

#include <stdexcept>

extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
Expand Down Expand Up @@ -124,9 +126,37 @@ std::string AudioProperties::getChannelDescription() const
#endif
}

MetadatasMap AudioProperties::getDataMap() const
size_t AudioProperties::getCodecId() const
{
if( ! _codecContext )
throw std::runtime_error( "unknown codec context" );
return _codecContext->codec_id;
}

size_t AudioProperties::getSampleRate() const
{
if( ! _codecContext )
throw std::runtime_error( "unknown codec context" );
return _codecContext->sample_rate;
}

size_t AudioProperties::getChannels() const
{
if( ! _codecContext )
throw std::runtime_error( "unknown codec context" );
return _codecContext->channels;
}

size_t AudioProperties::getBitRate() const
{
if( ! _codecContext )
throw std::runtime_error( "unknown codec context" );
return _codecContext->bit_rate;
}

PropertiesMap AudioProperties::getPropertiesAsMap() const
{
MetadatasMap dataMap;
PropertiesMap dataMap;

detail::add( dataMap, "streamId", getStreamId() );
detail::add( dataMap, "codecId", getCodecId() );
Expand Down
16 changes: 9 additions & 7 deletions src/AvTranscoder/mediaProperty/AudioProperties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,26 @@ class AvExport AudioProperties
std::string getChannelName() const;
std::string getChannelDescription() const;
size_t getStreamId() const { return _streamId; }
size_t getCodecId() const { return _codecContext->codec_id; }
size_t getSampleRate() const { return _codecContext->sample_rate; }
size_t getChannels() const { return _codecContext->channels; }
size_t getBitRate() const { return _codecContext->bit_rate; }
MetadatasMap& getMetadatas() { return _metadatas; }
size_t getCodecId() const;
size_t getSampleRate() const;
size_t getChannels() const;
size_t getBitRate() const;
PropertiesMap& getMetadatas() { return _metadatas; }

#ifndef SWIG
const AVFormatContext& getAVFormatContext() { return *_formatContext; }
AVCodecContext& getAVCodecContext() { return *_codecContext; }
#endif

MetadatasMap getDataMap() const;
PropertiesMap getPropertiesAsMap() const; ///< Return all audio properties as a map (name of property: value)

private:
const AVFormatContext* _formatContext; ///< Has link (no ownership)
AVCodecContext* _codecContext; ///< Has link (no ownership)
AVCodec* _codec; ///< Has link (no ownership)

size_t _streamId;
MetadatasMap _metadatas;
PropertiesMap _metadatas;
};

}
Expand Down
4 changes: 2 additions & 2 deletions src/AvTranscoder/mediaProperty/DataProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ DataProperties::DataProperties( const AVFormatContext* formatContext, const size
detail::fillMetadataDictionnary( _formatContext->streams[index]->metadata, _metadatas );
}

MetadatasMap DataProperties::getDataMap() const
PropertiesMap DataProperties::getPropertiesAsMap() const
{
MetadatasMap dataMap;
PropertiesMap dataMap;

detail::add( dataMap, "streamId", _streamId );

Expand Down
8 changes: 5 additions & 3 deletions src/AvTranscoder/mediaProperty/DataProperties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ class AvExport DataProperties
DataProperties( const AVFormatContext* formatContext, const size_t index );

size_t getStreamId() const { return _streamId; }
MetadatasMap& getMetadatas() { return _metadatas; }
PropertiesMap& getMetadatas() { return _metadatas; }

#ifndef SWIG
const AVFormatContext& getAVFormatContext() { return *_formatContext; }
#endif

MetadatasMap getDataMap() const;
PropertiesMap getPropertiesAsMap() const; ///< Return all data properties as a map (name of property: value)

private:
void detectAncillaryData();
Expand All @@ -30,7 +32,7 @@ class AvExport DataProperties
const AVFormatContext* _formatContext; ///< Has link (no ownership)

size_t _streamId;
MetadatasMap _metadatas;
PropertiesMap _metadatas;
};

}
Expand Down
68 changes: 66 additions & 2 deletions src/AvTranscoder/mediaProperty/FileProperties.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "FileProperties.hpp"

#include <stdexcept>

namespace avtranscoder
{

Expand All @@ -16,10 +18,72 @@ FileProperties::FileProperties( const AVFormatContext* formatContext )
detail::fillMetadataDictionnary( _formatContext->metadata, _metadatas );
}

std::string FileProperties::getFilename() const
{
if( ! _formatContext )
throw std::runtime_error( "unknown format context" );
return _formatContext->filename;
}

std::string FileProperties::getFormatName() const
{
if( ! _formatContext || ! _formatContext->iformat )
throw std::runtime_error( "unknown format context" );
return _formatContext->iformat->name;
}

std::string FileProperties::getFormatLongName() const
{
if( ! _formatContext || ! _formatContext->iformat )
throw std::runtime_error( "unknown format context" );
return _formatContext->iformat->long_name;
}

size_t FileProperties::getProgramsCount() const
{
if( ! _formatContext )
throw std::runtime_error( "unknown format context" );
return _formatContext->nb_programs;
}

double FileProperties::getStartTime() const
{
if( ! _formatContext )
throw std::runtime_error( "unknown format context" );
return 1.0 * (unsigned int)_formatContext->start_time / AV_TIME_BASE;
}

double FileProperties::getDuration() const
{
if( ! _formatContext )
throw std::runtime_error( "unknown format context" );
return 1.0 * _formatContext->duration / AV_TIME_BASE;
}

size_t FileProperties::getBitRate() const
{
if( ! _formatContext )
throw std::runtime_error( "unknown format context" );
return _formatContext->bit_rate;
}

size_t FileProperties::getPacketSize() const
{
if( ! _formatContext )
throw std::runtime_error( "unknown format context" );
return _formatContext->packet_size;
}

size_t FileProperties::getNbStreams() const
{
if( ! _formatContext )
throw std::runtime_error( "unknown format context" );
return _formatContext->nb_streams;
}

MetadatasMap FileProperties::getDataMap() const
PropertiesMap FileProperties::getPropertiesAsMap() const
{
MetadatasMap dataMap;
PropertiesMap dataMap;

detail::add( dataMap, "filename", getFilename() );
detail::add( dataMap, "formatName", getFormatName() );
Expand Down
26 changes: 14 additions & 12 deletions src/AvTranscoder/mediaProperty/FileProperties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ class AvExport FileProperties
public:
FileProperties( const AVFormatContext* formatContext );

std::string getFilename() const { return _formatContext->filename; }
std::string getFormatName() const { return _formatContext->iformat->name; }
std::string getFormatLongName() const { return _formatContext->iformat->long_name; }
std::string getFilename() const;
std::string getFormatName() const;
std::string getFormatLongName() const;

size_t getProgramsCount() const { return _formatContext->nb_programs; }
double getStartTime() const { return 1.0 * (unsigned int)_formatContext->start_time / AV_TIME_BASE; }
double getDuration() const { return 1.0 * _formatContext->duration / AV_TIME_BASE; }
size_t getBitRate() const { return _formatContext->bit_rate; }
size_t getPacketSize() const { return _formatContext->packet_size; }
size_t getProgramsCount() const;
double getStartTime() const;
double getDuration() const;
size_t getBitRate() const;
size_t getPacketSize() const;

MetadatasMap& getMetadatas() { return _metadatas; }
PropertiesMap& getMetadatas() { return _metadatas; }

size_t getNbStreams() const { return _formatContext->nb_streams; }
size_t getNbStreams() const;
size_t getNbVideoStreams() const { return _videoStreams.size(); }
size_t getNbAudioStreams() const { return _audioStreams.size(); }
size_t getNbDataStreams() const { return _dataStreams.size(); }
Expand All @@ -58,9 +58,11 @@ class AvExport FileProperties
std::vector< avtranscoder::UnknownProperties >& getUnknownPropertiesProperties() { return _unknownStreams; }
const std::vector< avtranscoder::UnknownProperties >& getUnknownPropertiesProperties() const { return _unknownStreams; }

#ifndef SWIG
const AVFormatContext& getAVFormatContext() { return *_formatContext; }
#endif

MetadatasMap getDataMap() const;
PropertiesMap getPropertiesAsMap() const; ///< Return all file properties as a map (name of property: value)

private:
const AVFormatContext* _formatContext; ///< Has link (no ownership)
Expand All @@ -72,7 +74,7 @@ class AvExport FileProperties
std::vector< AttachementProperties > _attachementStreams; ///< Array of properties per attachement stream
std::vector< UnknownProperties > _unknownStreams; ///< Array of properties per unknown stream

MetadatasMap _metadatas;
PropertiesMap _metadatas;
};

}
Expand Down
4 changes: 2 additions & 2 deletions src/AvTranscoder/mediaProperty/SubtitleProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ SubtitleProperties::SubtitleProperties( const AVFormatContext* formatContext, co
detail::fillMetadataDictionnary( _formatContext->streams[index]->metadata, _metadatas );
}

MetadatasMap SubtitleProperties::getDataMap() const
PropertiesMap SubtitleProperties::getPropertiesAsMap() const
{
MetadatasMap dataMap;
PropertiesMap dataMap;

detail::add( dataMap, "streamId", _streamId );

Expand Down
8 changes: 5 additions & 3 deletions src/AvTranscoder/mediaProperty/SubtitleProperties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,19 @@ class AvExport SubtitleProperties
SubtitleProperties( const AVFormatContext* formatContext, const size_t index );

size_t getStreamId() const { return _streamId; }
MetadatasMap& getMetadatas() { return _metadatas; }
PropertiesMap& getMetadatas() { return _metadatas; }

#ifndef SWIG
const AVFormatContext& getAVFormatContext() { return *_formatContext; }
#endif

MetadatasMap getDataMap() const;
PropertiesMap getPropertiesAsMap() const; ///< Return all subtitle properties as a map (name of property: value)

private:
const AVFormatContext* _formatContext; ///< Has link (no ownership)

size_t _streamId;
MetadatasMap _metadatas;
PropertiesMap _metadatas;
};

}
Expand Down
4 changes: 2 additions & 2 deletions src/AvTranscoder/mediaProperty/UnknownProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ UnknownProperties::UnknownProperties( const AVFormatContext* formatContext, cons
detail::fillMetadataDictionnary( _formatContext->streams[index]->metadata, _metadatas );
}

MetadatasMap UnknownProperties::getDataMap() const
PropertiesMap UnknownProperties::getPropertiesAsMap() const
{
MetadatasMap dataMap;
PropertiesMap dataMap;

detail::add( dataMap, "streamId", _streamId );

Expand Down
8 changes: 5 additions & 3 deletions src/AvTranscoder/mediaProperty/UnknownProperties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,19 @@ class AvExport UnknownProperties
UnknownProperties( const AVFormatContext* formatContext, const size_t index );

size_t getStreamId() const { return _streamId; }
MetadatasMap& getMetadatas() { return _metadatas; }
PropertiesMap& getMetadatas() { return _metadatas; }

#ifndef SWIG
const AVFormatContext& getAVFormatContext() { return *_formatContext; }
#endif

MetadatasMap getDataMap() const;
PropertiesMap getPropertiesAsMap() const; ///< Return unknown properties as a map (name of property: value)

private:
const AVFormatContext* _formatContext; ///< Has link (no ownership)

size_t _streamId;
MetadatasMap _metadatas;
PropertiesMap _metadatas;
};

}
Expand Down
Loading