Skip to content

Commit 7fa3b43

Browse files
theandi666Android (Google) Code Review
authored andcommitted
Merge "Add an option to dump the raw stream to a file in the stagefright cmdline tool."
2 parents e45beeb + a175453 commit 7fa3b43

1 file changed

Lines changed: 46 additions & 1 deletion

File tree

cmds/stagefright/stagefright.cpp

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,39 @@ static void displayAVCProfileLevelIfPossible(const sp<MetaData>& meta) {
133133
}
134134
}
135135

136+
static void dumpSource(const sp<MediaSource> &source, const String8 &filename) {
137+
FILE *out = fopen(filename.string(), "wb");
138+
139+
CHECK_EQ((status_t)OK, source->start());
140+
141+
status_t err;
142+
for (;;) {
143+
MediaBuffer *mbuf;
144+
err = source->read(&mbuf);
145+
146+
if (err == INFO_FORMAT_CHANGED) {
147+
continue;
148+
} else if (err != OK) {
149+
break;
150+
}
151+
152+
CHECK_EQ(
153+
fwrite((const uint8_t *)mbuf->data() + mbuf->range_offset(),
154+
1,
155+
mbuf->range_length(),
156+
out),
157+
(ssize_t)mbuf->range_length());
158+
159+
mbuf->release();
160+
mbuf = NULL;
161+
}
162+
163+
CHECK_EQ((status_t)OK, source->stop());
164+
165+
fclose(out);
166+
out = NULL;
167+
}
168+
136169
static void playSource(OMXClient *client, sp<MediaSource> &source) {
137170
sp<MetaData> meta = source->getFormat();
138171

@@ -578,6 +611,7 @@ static void usage(const char *me) {
578611
"(video only)\n");
579612
fprintf(stderr, " -S allocate buffers from a surface\n");
580613
fprintf(stderr, " -T allocate buffers from a surface texture\n");
614+
fprintf(stderr, " -d(ump) filename (raw stream data to a file)\n");
581615
}
582616

583617
int main(int argc, char **argv) {
@@ -590,6 +624,8 @@ int main(int argc, char **argv) {
590624
bool seekTest = false;
591625
bool useSurfaceAlloc = false;
592626
bool useSurfaceTexAlloc = false;
627+
bool dumpStream = false;
628+
String8 dumpStreamFilename;
593629
gNumRepetitions = 1;
594630
gMaxNumFrames = 0;
595631
gReproduceBug = -1;
@@ -604,14 +640,21 @@ int main(int argc, char **argv) {
604640
sp<LiveSession> liveSession;
605641

606642
int res;
607-
while ((res = getopt(argc, argv, "han:lm:b:ptsrow:kxST")) >= 0) {
643+
while ((res = getopt(argc, argv, "han:lm:b:ptsrow:kxSTd:")) >= 0) {
608644
switch (res) {
609645
case 'a':
610646
{
611647
audioOnly = true;
612648
break;
613649
}
614650

651+
case 'd':
652+
{
653+
dumpStream = true;
654+
dumpStreamFilename.setTo(optarg);
655+
break;
656+
}
657+
615658
case 'l':
616659
{
617660
listComponents = true;
@@ -1062,6 +1105,8 @@ int main(int argc, char **argv) {
10621105

10631106
if (gWriteMP4) {
10641107
writeSourcesToMP4(mediaSources, syncInfoPresent);
1108+
} else if (dumpStream) {
1109+
dumpSource(mediaSource, dumpStreamFilename);
10651110
} else if (seekTest) {
10661111
performSeekTest(mediaSource);
10671112
} else {

0 commit comments

Comments
 (0)