Browse files

stream: support passing in an `ogg_packet` instance directly

  • Loading branch information...
1 parent 658facc commit 498d5bc3e06fd89f58e29dbf16a9d4261024b788 @TooTallNate committed Dec 9, 2012
Showing with 33 additions and 1 deletion.
  1. +5 −1 lib/stream.js
  2. +28 −0 test/encoder.js
View
6 lib/stream.js
@@ -148,13 +148,17 @@ OggStream.prototype.pagein = function (page, fn) {
* Submits a raw packet to the streaming layer, so that it
* can be formed into a page.
*
- * @param {Buffer} packet `ogg_packet` instance
+ * @param {Buffer|ogg_packet} packet `ogg_packet` instance
* @param {Function} fn callback function
* @api public
*/
OggStream.prototype.packetin = function (packet, fn) {
debug('packetin()');
+
+ // support passing in an `ogg_packet` struct instance directly
+ if (packet.buffer) packet = packet.buffer;
+
if (this._writingPacket) {
debug('need to wait for "packetin" event before writing');
this.once('packetin', this.packetin.bind(this, packet, fn));
View
28 test/encoder.js
@@ -44,6 +44,34 @@ describe('Encoder', function () {
});
});
+ it('should support passing in an `ogg_struct` instance directly', function (done) {
+ var e = new Encoder();
+ // flow...
+ e.resume();
+
+ e.on('end', done);
+ var s = e.stream();
+
+ // create `ogg_packet`
+ var data = new Buffer('test');
+ var packet = new ogg_packet();
+ packet.packet = data;
+ packet.bytes = data.length;
+ packet.b_o_s = 1;
+ packet.e_o_s = 1;
+ packet.granulepos = 0;
+ packet.packetno = 0;
+
+ // pass in the `ogg_packet` instance directly
+ s.packetin(packet, function (err) {
+ if (err) return done(err);
+ s.pageout(function (err) {
+ if (err) return done(err);
+ // wait for "end" event...
+ });
+ });
+ });
+
});
describe('with three .stream()s', function () {

0 comments on commit 498d5bc

Please sign in to comment.