-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.cpp
More file actions
177 lines (141 loc) · 5.17 KB
/
Copy pathmain.cpp
File metadata and controls
177 lines (141 loc) · 5.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include <primo/avblocks/avb.h>
#include <primo/platform/reference++.h>
#include <primo/platform/error_facility.h>
#include <primo/platform/ustring.h>
#include "AvbUtil.h"
#include "util.h"
#include "options.h"
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace primo::avblocks;
using namespace primo::codecs;
using namespace std;
void printVideo(VideoStreamInfo* vsi)
{
int32_t bitrate = vsi->bitrate();
BitrateMode::Enum bitrateMode = (BitrateMode::Enum)vsi->bitrateMode();
primo::codecs::ColorFormat::Enum color = vsi->colorFormat();
int32_t dar_width = vsi->displayRatioWidth();
int32_t dar_height = vsi->displayRatioHeight();
bool frameBottomUp = vsi->frameBottomUp() == true;
int32_t height = vsi->frameHeight();
int32_t width = vsi->frameWidth();
double rate = vsi->frameRate();
ScanType::Enum scanType = vsi->scanType();
cout << "frame size: " << width << "x" << height << endl;
cout << "display ratio: " << dar_width << ":" << dar_height << endl;
cout << "frame rate: " << rate << endl;
cout << "color format: " << getColorFormatName(color) << endl;
cout << "bitrate: " << bitrate << ", mode: " << getBitrateModeName(bitrateMode) << endl;
cout << "scan type: " << getScanTypeName(scanType) << endl;
cout << "frame bottom up: " << frameBottomUp << endl;
}
void printAudio(AudioStreamInfo* asi)
{
uint32_t bitrate = asi->bitrate();
BitrateMode::Enum bitrateMode = (BitrateMode::Enum)asi->bitrateMode();
uint32_t bitsPerSample = asi->bitsPerSample();
uint32_t bytesPerFrame = asi->bytesPerFrame();
uint32_t channelLayout = asi->channelLayout();
uint32_t channels = asi->channels();
uint32_t flags = asi->pcmFlags();
uint32_t rate = asi->sampleRate();
cout << "sample rate: " << rate << endl;
cout << "channels: " << channels << endl;
cout << "bits per sample: " << bitsPerSample << endl;
cout << "bytes per frame: " << bytesPerFrame << endl;
cout << "bitrate: " << bitrate << ", mode: " << getBitrateModeName(bitrateMode) << endl;
cout << "channel layout: " << channelLayout << endl;
cout << "flags: " << flags << endl;
}
void printStreams(MediaInfo * info)
{
cout << "file: " << primo::ustring(info->inputs()->at(0)->file()) << endl;
for (int outSocketIndex = 0; outSocketIndex < info->outputs()->count(); outSocketIndex++)
{
MediaSocket * socket = info->outputs()->at(outSocketIndex);
StreamType::Enum containerType = socket->streamType();
cout << "container: " << getStreamTypeName(containerType) << endl;
MediaPinList* pins = socket->pins();
int32_t streamsCount = pins->count();
cout << "streams: " << streamsCount << endl;
cout << endl;
for (int i=0; i < streamsCount; ++i)
{
StreamInfo* psi = pins->at(i)->streamInfo();
MediaType::Enum mediaType = psi->mediaType();
cout << "stream #" << i << " " << getMediaTypeName(mediaType) << endl;
StreamType::Enum streamType = psi->streamType();
cout << "type: " << getStreamTypeName(streamType);
StreamSubType::Enum streamSubType = psi->streamSubType();
cout << ", subtype: " << getStreamSubTypeName(streamSubType) << endl;
int32_t id = psi->ID();
cout << "id: " << id << endl;
double duration = psi->duration();
cout << "duration: " << duration << endl;
if (MediaType::Video == mediaType)
{
VideoStreamInfo* vsi = static_cast<VideoStreamInfo*>(psi);
printVideo(vsi);
}
else if (MediaType::Audio == mediaType)
{
AudioStreamInfo* asi = static_cast<AudioStreamInfo*>(psi);
printAudio(asi);
}
else
{
cout << endl;
}
cout << std::endl;
}
}
}
void printError(const primo::error::ErrorInfo* e)
{
if (primo::error::ErrorFacility::Success == e->facility())
{
cout << "Success";
}
else
{
if (e->message())
{
cout << primo::ustring(e->message()) << " ";
}
cout << "(facility:" << e->facility() << " error:" << e->code() << ")" << endl;
}
cout << endl;
}
bool avInfo(Options& opt)
{
auto info = primo::make_ref(Library::createMediaInfo());
info->inputs()->at(0)->setFile(primo::ustring(opt.avfile));
if(info->open())
{
printStreams(info.get());
return true;
}
else
{
printError(info->error());
return false;
}
}
int main(int argc, char* argv[])
{
Options opt;
switch(prepareOptions(opt, argc, argv))
{
case Command: return 0;
case Error: return 1;
case Parsed: break;
}
Library::initialize();
// Library::setLicense("<license-xml-string>");
bool avInfoResult = avInfo(opt);
Library::shutdown();
return avInfoResult ? 0 : 1;
}