1 /*
2 ** Copyright 2004, Marcus Overhagen. All rights reserved.
3 ** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
4 **
5 ** Distributed under the terms of the MIT License.
6 */
7
8
9 #include "MediaPlugin.h"
10 #include "ReaderPlugin.h"
11 #include "MediaExtractor.h"
12
13 #include <OS.h>
14 #include <File.h>
15
16 #include <string.h>
17 #include <stdio.h>
18
19
20 #define TRACE_THIS 1
21 #if TRACE_THIS
22 #define TRACE printf
23 #else
24 #define TRACE ((void)0)
25 #endif
26
27 void *cookies[100];
28
29
30 int
main(int argc,char * argv[])31 main(int argc, char *argv[])
32 {
33 if (argc < 2) {
34 // missing argument
35 char *name = strrchr(argv[0], '/');
36 name = name ? name + 1 : argv[0];
37 fprintf(stderr, "usage: %s <media-file>\n", name);
38 return -1;
39 }
40
41 TRACE("\n\n");
42
43 TRACE("main: creating plugin...\n");
44
45 MediaPlugin *plugin = instantiate_plugin();
46
47 TRACE("main: creating reader...\n");
48
49 ReaderPlugin *readerplugin;
50 readerplugin = dynamic_cast<ReaderPlugin *>(plugin);
51
52 Reader *reader = readerplugin->NewReader();
53
54 TRACE("main: opening source file...\n");
55
56 BDataIO *source = new BFile(argv[1], B_READ_ONLY);
57
58 TRACE("main: calling setup...\n");
59
60 reader->Setup(source);
61
62 TRACE("main: creating ...\n");
63
64 TRACE("main: copyright: \"%s\"\n", reader->Copyright());
65
66 status_t status;
67 int32 streamCount;
68
69 status = reader->Sniff(&streamCount);
70 if (status != B_OK) {
71 TRACE("main: Sniff() failed with error %lx (%s)\n", status, strerror(status));
72 goto err;
73 }
74
75 TRACE("main: Sniff() found %ld streams\n", streamCount);
76
77 for (int i = 0; i < streamCount; i++) {
78 TRACE("main: calling AllocateCookie(stream = %d)\n", i);
79 status = reader->AllocateCookie(i, &cookies[i]);
80 if (status != B_OK) {
81 TRACE("main: AllocateCookie(stream = %d) failed with error 0x%lx (%s)\n",
82 i, status, strerror(status));
83 goto err;
84 }
85 }
86
87 for (int i = 0; i < streamCount; i++) {
88 TRACE("main: calling GetStreamInfo(stream = %d)\n", i);
89 int64 frameCount;
90 bigtime_t duration;
91 media_format format;
92 const void *infoBuffer;
93 size_t infoSize;
94 status = reader->GetStreamInfo(cookies[i], &frameCount, &duration, &format,
95 &infoBuffer, &infoSize);
96 if (status != B_OK) {
97 TRACE("main: GetStreamInfo(stream = %d) failed with error 0x%lx (%s)\n",
98 i, status, strerror(status));
99 goto err;
100 }
101 TRACE("main: GetStreamInfo(stream = %d) result: %lld frames, %.6f sec\n",
102 i, frameCount, duration / 1000000.0);
103 }
104
105 for (int i = 0; i < streamCount; i++) {
106 const void *chunkBuffer;
107 size_t chunkSize;
108 media_header mediaHeader;
109 for (int j = 0; j < 5; j++) {
110 status = reader->GetNextChunk(cookies[i], &chunkBuffer, &chunkSize, &mediaHeader);
111 if (status != B_OK) {
112 TRACE("main: GetNextChunk(stream = %d, chunk = %d) failed with error 0x%lx (%s)\n",
113 i, j, status, strerror(status));
114 break;
115 }
116 }
117
118 int64 frame;
119 bigtime_t time;
120
121 time = 1000000; // 1 sec
122 TRACE("main: calling Seek(stream = %d, time %.6f forward)\n", i, time / 1000000.0);
123 status = reader->Seek(cookies[i],
124 B_MEDIA_SEEK_TO_TIME | B_MEDIA_SEEK_CLOSEST_FORWARD, &frame, &time);
125 TRACE("main: Seek result: time %.6f, frame %lld\n", time / 1000000.0, frame);
126
127 frame = 1000;
128 TRACE("main: calling Seek(stream = %d, frame %lld forward)\n", i, frame);
129 status = reader->Seek(cookies[i],
130 B_MEDIA_SEEK_TO_FRAME | B_MEDIA_SEEK_CLOSEST_FORWARD, &frame, &time);
131 TRACE("main: Seek result: time %.6f, frame %lld\n", time / 1000000.0, frame);
132
133 time = 1000000; // 1 sec
134 TRACE("main: calling Seek(stream = %d, time %.6f backward)\n", i, time / 1000000.0);
135 status = reader->Seek(cookies[i],
136 B_MEDIA_SEEK_TO_TIME | B_MEDIA_SEEK_CLOSEST_BACKWARD, &frame, &time);
137 TRACE("main: Seek result: time %.6f, frame %lld\n", time / 1000000.0, frame);
138
139 frame = 1000;
140 TRACE("main: calling Seek(stream = %d, frame %lld backward)\n", i, frame);
141 status = reader->Seek(cookies[i],
142 B_MEDIA_SEEK_TO_FRAME | B_MEDIA_SEEK_CLOSEST_BACKWARD, &frame, &time);
143 TRACE("main: Seek result: time %.6f, frame %lld\n", time / 1000000.0, frame);
144 }
145
146 for (int i = 0; i < streamCount; i++) {
147 TRACE("main: calling FreeCookie(stream = %d)\n", i);
148 status = reader->FreeCookie(cookies[i]);
149 if (status != B_OK) {
150 TRACE("main: FreeCookie(stream = %d) failed with error 0x%lx (%s)\n",
151 i, status, strerror(status));
152 goto err;
153 }
154 }
155
156 err:
157 delete reader;
158 delete plugin;
159 delete source;
160
161 return 0;
162 }
163
164
165 status_t
_get_format_for_description(media_format * out_format,const media_format_description & in_desc)166 _get_format_for_description(media_format *out_format, const media_format_description &in_desc)
167 {
168 return B_OK;
169 }
170
171 namespace BPrivate {
172 namespace media {
173
174 status_t
GetNextChunk(int32 stream,const void ** chunkBuffer,size_t * chunkSize,media_header * mediaHeader)175 MediaExtractor::GetNextChunk(int32 stream,
176 const void **chunkBuffer, size_t *chunkSize,
177 media_header *mediaHeader)
178 {
179 return B_ERROR;
180 }
181
182 } // namespace media
183 } // namespace BPrivate
184