Skip to content
Browse files

null writer for testing without worrying about output

  • Loading branch information...
1 parent 64617c0 commit 4db29235de3dea0059dddf9464e991ca7c31af35 @benvanik committed Nov 27, 2011
Showing with 94 additions and 16 deletions.
  1. +4 −0 examples/transcode.js
  2. +2 −2 lib/transcoding.js
  3. +4 −1 src/io/iohandle.cpp
  4. +34 −0 src/io/nullwriter.cpp
  5. +28 −0 src/io/nullwriter.h
  6. +1 −1 src/query.cpp
  7. +18 −10 src/task.cpp
  8. +2 −2 src/task.h
  9. +1 −0 wscript
View
4 examples/transcode.js
@@ -47,6 +47,8 @@ var source;
if (inputFile == '-') {
// STDIN
source = process.stdin;
+} else if (inputFile == 'null') {
+ source = null;
} else if (inputFile.indexOf('http') == 0) {
// Web request
var sourceUrl = url.parse(inputFile);
@@ -96,6 +98,8 @@ if (opts.args.length >= 2) {
if (outputFile == '-') {
// STDOUT
target = process.stdout;
+ } else if (outputFile == 'null') {
+ target = null;
} else if (outputFile.indexOf('http') == 0) {
// TODO: setup server for streaming?
console.log('not yet implemented: HTTP serving');
View
4 lib/transcoding.js
@@ -25,13 +25,13 @@ exports.queryInfo = function(source, callback) {
};
exports.createTask = function(source, target, profile, opt_options) {
- return new binding.Task(source, target, profile, opt_options || {});
+ return new binding.Task(source, target, profile, opt_options);
};
exports.process = function(source, target, profile, opt_options, callback) {
var sourceInfoStash = null;
var targetInfoStash = null;
- var task = new binding.Task(source, target, profile, opt_options || {});
+ var task = new binding.Task(source, target, profile, opt_options);
task.on('begin', function(sourceInfo, targetInfo) {
sourceInfoStash = sourceInfo;
targetInfoStash = targetInfo;
View
5 src/io/iohandle.cpp
@@ -1,6 +1,7 @@
#include "iohandle.h"
#include "filereader.h"
#include "filewriter.h"
+#include "nullwriter.h"
#include "streamreader.h"
#include "streamwriter.h"
@@ -60,7 +61,9 @@ IOWriter::~IOWriter() {
IOWriter* IOWriter::Create(Handle<Object> source, size_t maxBufferedBytes) {
HandleScope scope;
- if (source->IsStringObject()) {
+ if (source.IsEmpty() || source->IsNull()) {
+ return new NullWriter();
+ } else if (source->IsStringObject()) {
return new FileWriter(source);
} else {
return new StreamWriter(source,
View
34 src/io/nullwriter.cpp
@@ -0,0 +1,34 @@
+#include "nullwriter.h"
+
+using namespace transcoding;
+using namespace transcoding::io;
+
+NullWriter::NullWriter() :
+ IOWriter(Object::New()) {
+ HandleScope scope;
+ TC_LOG_D("NullWriter::NullWriter()\n");
+}
+
+NullWriter::~NullWriter() {
+ TC_LOG_D("NullWriter::~NullWriter()\n");
+}
+
+int NullWriter::Open() {
+ AVIOContext* s = NULL;
+ int ret = avio_open_dyn_buf(&s);
+ if (ret) {
+ TC_LOG_D("NullWriter::Open(): failed (%d)\n", ret);
+ return ret;
+ }
+ TC_LOG_D("NullWriter::Open()\n");
+ this->context = s;
+ return 0;
+}
+
+void NullWriter::Close() {
+ TC_LOG_D("NullWriter::Close()\n");
+ uint8_t* buffer = NULL;
+ int size = avio_close_dyn_buf(this->context, &buffer);
+ av_free(buffer);
+ this->context = NULL;
+}
View
28 src/io/nullwriter.h
@@ -0,0 +1,28 @@
+#include <node.h>
+#include <v8.h>
+#include "../utils.h"
+#include "iohandle.h"
+
+#ifndef NODE_TRANSCODING_IO_NULLWRITER
+#define NODE_TRANSCODING_IO_NULLWRITER
+
+using namespace v8;
+
+namespace transcoding {
+namespace io {
+
+class NullWriter : public IOWriter {
+public:
+ NullWriter();
+ virtual ~NullWriter();
+
+ virtual int Open();
+ virtual void Close();
+
+public:
+};
+
+}; // io
+}; // transcoding
+
+#endif // NODE_TRANSCODING_IO_NULLWRITER
View
2 src/query.cpp
@@ -64,8 +64,8 @@ Handle<Value> Query::GetSource(Local<String> property,
Handle<Value> Query::Start(const Arguments& args) {
TC_LOG_D("Query::Start()\n");
- Query* query = ObjectWrap::Unwrap<Query>(args.This());
HandleScope scope;
+ Query* query = ObjectWrap::Unwrap<Query>(args.This());
assert(!query->context);
View
28 src/task.cpp
@@ -42,25 +42,33 @@ void Task::Init(Handle<Object> target) {
Handle<Value> Task::New(const Arguments& args) {
HandleScope scope;
- Local<Object> source = args[0]->ToObject();
- Local<Object> target = args[1]->ToObject();
- Local<Object> profile = args[2]->ToObject();
- Local<Object> options = args[3]->ToObject();
- Task* task = new Task(source, target, profile, options);
+ Task* task = new Task(
+ args[0]->ToObject(),
+ args[1],
+ args[2]->ToObject(),
+ args[3]);
task->Wrap(args.This());
return scope.Close(args.This());
}
-Task::Task(Handle<Object> source, Handle<Object> target, Handle<Object> profile,
- Handle<Object> options) :
+Task::Task(Handle<Object> source, Handle<Value> targetValue,
+ Handle<Object> profile, Handle<Value> optionsValue) :
context(NULL), abort(false), err(0) {
TC_LOG_D("Task::Task()\n");
HandleScope scope;
this->source = Persistent<Object>::New(source);
- this->target = Persistent<Object>::New(target);
+ if (targetValue.IsEmpty() || targetValue->IsNull()) {
+ // Null target
+ } else {
+ this->target = Persistent<Object>::New(targetValue.As<Object>());
+ }
this->profile = Persistent<Object>::New(profile);
- this->options = Persistent<Object>::New(options);
+ if (optionsValue.IsEmpty() || optionsValue->IsNull()) {
+ this->options = Persistent<Object>::New(Object::New());
+ } else {
+ this->options = Persistent<Object>::New(optionsValue.As<Object>());
+ }
memset(&this->progress, 0, sizeof(this->progress));
@@ -170,7 +178,7 @@ Handle<Value> Task::Start(const Arguments& args) {
// Start thread
int status = uv_queue_work(uv_default_loop(), req,
- ThreadWorker, ThreadWorkerAfter);
+ ThreadWorker, ThreadWorkerAfter);
assert(status == 0);
return scope.Close(Undefined());
View
4 src/task.h
@@ -34,8 +34,8 @@ class Task : public node::ObjectWrap {
static Handle<Value> New(const Arguments& args);
public:
- Task(Handle<Object> source, Handle<Object> target, Handle<Object> profile,
- Handle<Object> options);
+ Task(Handle<Object> source, Handle<Value> targetValue,
+ Handle<Object> profile, Handle<Value> optionsValue);
~Task();
static Handle<Value> GetSource(Local<String> property,
View
1 wscript
@@ -45,6 +45,7 @@ def build(bld):
'src/io/filewriter.cpp',
'src/io/io.cpp',
'src/io/iohandle.cpp',
+ 'src/io/nullwriter.cpp',
'src/io/streamreader.cpp',
'src/io/streamwriter.cpp',
]

0 comments on commit 4db2923

Please sign in to comment.
Something went wrong with that request. Please try again.