added dumpvtt app
Change-Id: I9eba00412bbd05641dafd1a6cfc4656bda8bb8c2
This commit is contained in:
parent
adebb53754
commit
282a67599c
8
Makefile
8
Makefile
@ -4,8 +4,9 @@ LIBWEBM := libwebm.a
|
||||
WEBMOBJS := mkvparser.o mkvreader.o mkvmuxer.o mkvmuxerutil.o mkvwriter.o
|
||||
OBJECTS1 := sample.o
|
||||
OBJECTS2 := sample_muxer.o
|
||||
OBJECTS3 := dumpvtt.o vttreader.o webvttparser.o
|
||||
INCLUDES := -I.
|
||||
EXES := samplemuxer sample
|
||||
EXES := samplemuxer sample dumpvtt
|
||||
|
||||
all: $(EXES)
|
||||
|
||||
@ -15,6 +16,9 @@ sample: sample.o $(LIBWEBM)
|
||||
samplemuxer: sample_muxer.o $(LIBWEBM)
|
||||
$(CXX) $^ -o $@
|
||||
|
||||
dumpvtt: $(OBJECTS3)
|
||||
$(CXX) $^ -o $@
|
||||
|
||||
libwebm.a: $(WEBMOBJS)
|
||||
$(AR) rcs $@ $^
|
||||
|
||||
@ -22,4 +26,4 @@ libwebm.a: $(WEBMOBJS)
|
||||
$(CXX) -c $(CXXFLAGS) $(INCLUDES) $< -o $@
|
||||
|
||||
clean:
|
||||
$(RM) -f $(OBJECTS1) $(OBJECTS2) $(WEBMOBJS) $(LIBWEBM) $(EXES) Makefile.bak
|
||||
$(RM) -f $(OBJECTS1) $(OBJECTS2) $(OBJECTS3) $(WEBMOBJS) $(LIBWEBM) $(EXES) Makefile.bak
|
||||
|
98
dumpvtt.cc
Normal file
98
dumpvtt.cc
Normal file
@ -0,0 +1,98 @@
|
||||
// Copyright (c) 2012 The WebM project authors. All Rights Reserved.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style license
|
||||
// that can be found in the LICENSE file in the root of the source
|
||||
// tree. An additional intellectual property rights grant can be found
|
||||
// in the file PATENTS. All contributing project authors may
|
||||
// be found in the AUTHORS file in the root of the source tree.
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include "./vttreader.h"
|
||||
#include "./webvttparser.h"
|
||||
|
||||
int main(int argc, const char* argv[]) {
|
||||
if (argc != 2) {
|
||||
fprintf(stdout, "usage: dumpvtt <vtt file>\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
libwebvtt::VttReader reader;
|
||||
const char* const filename = argv[1];
|
||||
|
||||
if (int e = reader.Open(filename)) {
|
||||
(void)e;
|
||||
fprintf(stderr, "open failed\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
libwebvtt::Parser parser(&reader);
|
||||
|
||||
if (int e = parser.Init()) {
|
||||
(void)e;
|
||||
fprintf(stderr, "parser init failed\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
for (libwebvtt::Cue cue;;) {
|
||||
const int e = parser.Parse(&cue);
|
||||
|
||||
if (e < 0) { // error
|
||||
fprintf(stderr, "error parsing cue\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (e > 0) // EOF
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
fprintf(stdout, "cue identifier: \"%s\"\n", cue.identifier.c_str());
|
||||
|
||||
const libwebvtt::Time& st = cue.start_time;
|
||||
fprintf(stdout, "cue start time: \"HH=%i MM=%i SS=%i SSS=%i\"\n",
|
||||
st.hours,
|
||||
st.minutes,
|
||||
st.seconds,
|
||||
st.milliseconds);
|
||||
|
||||
const libwebvtt::Time& sp = cue.stop_time;
|
||||
fprintf(stdout, "cue stop time: \"HH=%i MM=%i SS=%i SSS=%i\"\n",
|
||||
sp.hours,
|
||||
sp.minutes,
|
||||
sp.seconds,
|
||||
sp.milliseconds);
|
||||
|
||||
{
|
||||
typedef libwebvtt::Cue::settings_t::const_iterator iter_t;
|
||||
iter_t i = cue.settings.begin();
|
||||
const iter_t j = cue.settings.end();
|
||||
|
||||
if (i == j) {
|
||||
fprintf(stdout, "cue setting: <no settings present>\n");
|
||||
} else {
|
||||
while (i != j) {
|
||||
const libwebvtt::Setting& setting = *i++;
|
||||
fprintf(stdout, "cue setting: name=%s value=%s\n",
|
||||
setting.name.c_str(),
|
||||
setting.value.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
typedef libwebvtt::Cue::payload_t::const_iterator iter_t;
|
||||
iter_t i = cue.payload.begin();
|
||||
const iter_t j = cue.payload.end();
|
||||
|
||||
int idx = 1;
|
||||
while (i != j) {
|
||||
const std::string& payload = *i++;
|
||||
const char* const payload_str = payload.c_str();
|
||||
fprintf(stdout, "cue payload[%i]: \"%s\"\n", idx, payload_str);
|
||||
++idx;
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stdout, "\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
57
vttreader.cc
Normal file
57
vttreader.cc
Normal file
@ -0,0 +1,57 @@
|
||||
// Copyright (c) 2012 The WebM project authors. All Rights Reserved.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style license
|
||||
// that can be found in the LICENSE file in the root of the source
|
||||
// tree. An additional intellectual property rights grant can be found
|
||||
// in the file PATENTS. All contributing project authors may
|
||||
// be found in the AUTHORS file in the root of the source tree.
|
||||
|
||||
#include "./vttreader.h" // NOLINT
|
||||
|
||||
namespace libwebvtt {
|
||||
|
||||
VttReader::VttReader() : file_(NULL) {
|
||||
}
|
||||
|
||||
VttReader::~VttReader() {
|
||||
Close();
|
||||
}
|
||||
|
||||
int VttReader::Open(const char* filename) {
|
||||
if (filename == NULL || file_ != NULL)
|
||||
return -1;
|
||||
|
||||
file_ = fopen(filename, "rb");
|
||||
if (file_ == NULL)
|
||||
return -1;
|
||||
|
||||
return 0; // success
|
||||
}
|
||||
|
||||
void VttReader::Close() {
|
||||
if (file_) {
|
||||
fclose(file_);
|
||||
file_ = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int VttReader::GetChar(char* c) {
|
||||
if (c == NULL || file_ == NULL)
|
||||
return -1;
|
||||
|
||||
const int result = fgetc(file_);
|
||||
if (result != EOF) {
|
||||
*c = static_cast<char>(result);
|
||||
return 0; // success
|
||||
}
|
||||
|
||||
if (ferror(file_))
|
||||
return -1; // error
|
||||
|
||||
if (feof(file_))
|
||||
return 1; // EOF
|
||||
|
||||
return -1; // weird
|
||||
}
|
||||
|
||||
} // namespace libwebvtt
|
44
vttreader.h
Normal file
44
vttreader.h
Normal file
@ -0,0 +1,44 @@
|
||||
// Copyright (c) 2012 The WebM project authors. All Rights Reserved.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style license
|
||||
// that can be found in the LICENSE file in the root of the source
|
||||
// tree. An additional intellectual property rights grant can be found
|
||||
// in the file PATENTS. All contributing project authors may
|
||||
// be found in the AUTHORS file in the root of the source tree.
|
||||
|
||||
#ifndef VTTREADER_H_ // NOLINT
|
||||
#define VTTREADER_H_
|
||||
|
||||
#include <cstdio>
|
||||
#include "./webvttparser.h"
|
||||
|
||||
namespace libwebvtt {
|
||||
|
||||
class VttReader : public libwebvtt::Reader {
|
||||
public:
|
||||
VttReader();
|
||||
virtual ~VttReader();
|
||||
|
||||
// Open the file identified by |filename| in read-only mode, as a
|
||||
// binary stream of bytes. Returns 0 on success, negative if error.
|
||||
int Open(const char* filename);
|
||||
|
||||
// Closes the file stream. Note that the stream is automatically
|
||||
// closed when the VttReader object is destroyed.
|
||||
void Close();
|
||||
|
||||
// Reads the next character in the file stream, as per the semantics
|
||||
// of Reader::GetChar. Returns negative if error, 0 on success, and
|
||||
// positive if end-of-stream has been reached.
|
||||
virtual int GetChar(char* c);
|
||||
|
||||
private:
|
||||
FILE* file_;
|
||||
|
||||
VttReader(const VttReader&);
|
||||
VttReader& operator=(const VttReader&);
|
||||
};
|
||||
|
||||
} // namespace libwebvtt
|
||||
|
||||
#endif // VTTREADER_H_ // NOLINT
|
Loading…
Reference in New Issue
Block a user