Skip to content

Commit

Permalink
Add functions to get track metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
myrsloik committed Oct 27, 2024
1 parent 12a247d commit c25cf29
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/audiosource.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ struct BSAudioProperties {
double StartTime; /* in seconds */
};

struct LWAudioDecoder {
class LWAudioDecoder {
private:
AVFormatContext *FormatContext = nullptr;
AVCodecContext *CodecContext = nullptr;
Expand Down
29 changes: 28 additions & 1 deletion src/tracklist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,31 @@ int BestTrackList::GetNumTracks() const {

const BestTrackList::TrackInfo &BestTrackList::GetTrackInfo(int Track) const {
return TrackList[Track];
}
}

std::map<std::string, std::string> BestTrackList::GetFileMetadata() const {
std::map<std::string, std::string> Result;

auto Entry = av_dict_iterate(FormatContext->metadata, nullptr);
while (Entry) {
Result[Entry->key] = Entry->value;
Entry = av_dict_iterate(FormatContext->metadata, Entry);
}

return Result;
}

std::map<std::string, std::string> BestTrackList::GetTrackMetadata(int Track) const {
if (Track < 0 || Track >= FormatContext->nb_streams)
throw BestSourceException("Invalid track number");

std::map<std::string, std::string> Result;

auto Entry = av_dict_iterate(FormatContext->streams[Track]->metadata, nullptr);
while (Entry) {
Result[Entry->key] = Entry->value;
Entry = av_dict_iterate(FormatContext->streams[Track]->metadata, Entry);
}

return Result;
}
2 changes: 2 additions & 0 deletions src/tracklist.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ struct BestTrackList {
~BestTrackList();
[[nodiscard]] int GetNumTracks() const;
[[nodiscard]] const TrackInfo &GetTrackInfo(int Track) const;
[[nodiscard]] std::map<std::string, std::string> GetFileMetadata() const;
[[nodiscard]] std::map<std::string, std::string> GetTrackMetadata(int Track) const;
};

#endif
2 changes: 1 addition & 1 deletion src/videosource.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ struct BSVideoProperties {
int Rotation; /* A positive number in degrees */
};

struct LWVideoDecoder {
class LWVideoDecoder {
private:
AVFormatContext *FormatContext = nullptr;
AVCodecContext *CodecContext = nullptr;
Expand Down

0 comments on commit c25cf29

Please sign in to comment.