Skip to content

Commit

Permalink
null writer for testing without worrying about output
Browse files Browse the repository at this point in the history
  • Loading branch information
benvanik committed Nov 27, 2011
1 parent 64617c0 commit 4db2923
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 16 deletions.
4 changes: 4 additions & 0 deletions examples/transcode.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ var source;
if (inputFile == '-') { if (inputFile == '-') {
// STDIN // STDIN
source = process.stdin; source = process.stdin;
} else if (inputFile == 'null') {
source = null;
} else if (inputFile.indexOf('http') == 0) { } else if (inputFile.indexOf('http') == 0) {
// Web request // Web request
var sourceUrl = url.parse(inputFile); var sourceUrl = url.parse(inputFile);
Expand Down Expand Up @@ -96,6 +98,8 @@ if (opts.args.length >= 2) {
if (outputFile == '-') { if (outputFile == '-') {
// STDOUT // STDOUT
target = process.stdout; target = process.stdout;
} else if (outputFile == 'null') {
target = null;
} else if (outputFile.indexOf('http') == 0) { } else if (outputFile.indexOf('http') == 0) {
// TODO: setup server for streaming? // TODO: setup server for streaming?
console.log('not yet implemented: HTTP serving'); console.log('not yet implemented: HTTP serving');
Expand Down
4 changes: 2 additions & 2 deletions lib/transcoding.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ exports.queryInfo = function(source, callback) {
}; };


exports.createTask = function(source, target, profile, opt_options) { 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) { exports.process = function(source, target, profile, opt_options, callback) {
var sourceInfoStash = null; var sourceInfoStash = null;
var targetInfoStash = 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) { task.on('begin', function(sourceInfo, targetInfo) {
sourceInfoStash = sourceInfo; sourceInfoStash = sourceInfo;
targetInfoStash = targetInfo; targetInfoStash = targetInfo;
Expand Down
5 changes: 4 additions & 1 deletion src/io/iohandle.cpp
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "iohandle.h" #include "iohandle.h"
#include "filereader.h" #include "filereader.h"
#include "filewriter.h" #include "filewriter.h"
#include "nullwriter.h"
#include "streamreader.h" #include "streamreader.h"
#include "streamwriter.h" #include "streamwriter.h"


Expand Down Expand Up @@ -60,7 +61,9 @@ IOWriter::~IOWriter() {
IOWriter* IOWriter::Create(Handle<Object> source, size_t maxBufferedBytes) { IOWriter* IOWriter::Create(Handle<Object> source, size_t maxBufferedBytes) {
HandleScope scope; HandleScope scope;


if (source->IsStringObject()) { if (source.IsEmpty() || source->IsNull()) {
return new NullWriter();
} else if (source->IsStringObject()) {
return new FileWriter(source); return new FileWriter(source);
} else { } else {
return new StreamWriter(source, return new StreamWriter(source,
Expand Down
34 changes: 34 additions & 0 deletions src/io/nullwriter.cpp
Original file line number Original file line Diff line number Diff line change
@@ -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;
}
28 changes: 28 additions & 0 deletions src/io/nullwriter.h
Original file line number Original file line Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/query.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ Handle<Value> Query::GetSource(Local<String> property,
Handle<Value> Query::Start(const Arguments& args) { Handle<Value> Query::Start(const Arguments& args) {
TC_LOG_D("Query::Start()\n"); TC_LOG_D("Query::Start()\n");


Query* query = ObjectWrap::Unwrap<Query>(args.This());
HandleScope scope; HandleScope scope;
Query* query = ObjectWrap::Unwrap<Query>(args.This());


assert(!query->context); assert(!query->context);


Expand Down
28 changes: 18 additions & 10 deletions src/task.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -42,25 +42,33 @@ void Task::Init(Handle<Object> target) {


Handle<Value> Task::New(const Arguments& args) { Handle<Value> Task::New(const Arguments& args) {
HandleScope scope; HandleScope scope;
Local<Object> source = args[0]->ToObject(); Task* task = new Task(
Local<Object> target = args[1]->ToObject(); args[0]->ToObject(),
Local<Object> profile = args[2]->ToObject(); args[1],
Local<Object> options = args[3]->ToObject(); args[2]->ToObject(),
Task* task = new Task(source, target, profile, options); args[3]);
task->Wrap(args.This()); task->Wrap(args.This());
return scope.Close(args.This()); return scope.Close(args.This());
} }


Task::Task(Handle<Object> source, Handle<Object> target, Handle<Object> profile, Task::Task(Handle<Object> source, Handle<Value> targetValue,
Handle<Object> options) : Handle<Object> profile, Handle<Value> optionsValue) :
context(NULL), abort(false), err(0) { context(NULL), abort(false), err(0) {
TC_LOG_D("Task::Task()\n"); TC_LOG_D("Task::Task()\n");
HandleScope scope; HandleScope scope;


this->source = Persistent<Object>::New(source); 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->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)); memset(&this->progress, 0, sizeof(this->progress));


Expand Down Expand Up @@ -170,7 +178,7 @@ Handle<Value> Task::Start(const Arguments& args) {


// Start thread // Start thread
int status = uv_queue_work(uv_default_loop(), req, int status = uv_queue_work(uv_default_loop(), req,
ThreadWorker, ThreadWorkerAfter); ThreadWorker, ThreadWorkerAfter);
assert(status == 0); assert(status == 0);


return scope.Close(Undefined()); return scope.Close(Undefined());
Expand Down
4 changes: 2 additions & 2 deletions src/task.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class Task : public node::ObjectWrap {
static Handle<Value> New(const Arguments& args); static Handle<Value> New(const Arguments& args);


public: public:
Task(Handle<Object> source, Handle<Object> target, Handle<Object> profile, Task(Handle<Object> source, Handle<Value> targetValue,
Handle<Object> options); Handle<Object> profile, Handle<Value> optionsValue);
~Task(); ~Task();


static Handle<Value> GetSource(Local<String> property, static Handle<Value> GetSource(Local<String> property,
Expand Down
1 change: 1 addition & 0 deletions wscript
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def build(bld):
'src/io/filewriter.cpp', 'src/io/filewriter.cpp',
'src/io/io.cpp', 'src/io/io.cpp',
'src/io/iohandle.cpp', 'src/io/iohandle.cpp',
'src/io/nullwriter.cpp',
'src/io/streamreader.cpp', 'src/io/streamreader.cpp',
'src/io/streamwriter.cpp', 'src/io/streamwriter.cpp',
] ]

0 comments on commit 4db2923

Please sign in to comment.