Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 795e2c3649
Fetching contributors…

Cannot retrieve contributors at this time

file 78 lines (65 sloc) 2.426 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
#ifndef ASYNC_STACKED_VIDEO_H
#define ASYNC_STACKED_VIDEO_H

#include <vector>
#include <string>
#include <node.h>
#include <node_version.h>
#include "video_encoder.h"

struct push_request {
    unsigned int push_id;
    unsigned int fragment_id;
    const char *tmp_dir;
    unsigned char *data;
    int data_size;
    int x, y, w, h;
};

class AsyncStackedVideo;

struct async_encode_request {
    AsyncStackedVideo *video_obj;
    v8::Persistent<v8::Function> callback;
    char *error;
};

struct Rect {
    int x, y, w, h;
    Rect() {}
    Rect(int xx, int yy, int ww, int hh) : x(xx), y(yy), w(ww), h(hh) {}
    bool isNull() { return x == 0 && y == 0 && w == 0 && h == 0; }
};

class AsyncStackedVideo : public node::ObjectWrap {
    int width, height;

    VideoEncoder videoEncoder;

    std::string tmp_dir;
    unsigned int push_id, fragment_id;

#if NODE_VERSION_AT_LEAST(0,6,0)
    static void EIO_Push(eio_req *req);
    static void EIO_Encode(eio_req *req);
#else
    static int EIO_Push(eio_req *req);
    static int EIO_Encode(eio_req *req);
#endif
    static int EIO_PushAfter(eio_req *req);
    static int EIO_EncodeAfter(eio_req *req);

    static void push_fragment(unsigned char *frame, int width, int height,
        unsigned char *fragment, int x, int y, int w, int h);
    static Rect rect_dims(const char *fragment_name);

public:
    AsyncStackedVideo(int wwidth, int hheight);
    static void Initialize(v8::Handle<v8::Object> target);
    v8::Handle<v8::Value> Push(unsigned char *rect, int x, int y, int w, int h);
    void EndPush(unsigned long timeStamp=0);
    void SetOutputFile(const char *fileName);
    void SetQuality(int quality);
    void SetFrameRate(int frameRate);
    void SetKeyFrameInterval(int keyFrameInterval);

protected:
    static v8::Handle<v8::Value> New(const v8::Arguments &args);
    static v8::Handle<v8::Value> Push(const v8::Arguments &args);
    static v8::Handle<v8::Value> EndPush(const v8::Arguments &args);
    static v8::Handle<v8::Value> SetOutputFile(const v8::Arguments &args);
    static v8::Handle<v8::Value> SetQuality(const v8::Arguments &args);
    static v8::Handle<v8::Value> SetFrameRate(const v8::Arguments &args);
    static v8::Handle<v8::Value> SetKeyFrameInterval(const v8::Arguments &args);
    static v8::Handle<v8::Value> SetTmpDir(const v8::Arguments &args);
    static v8::Handle<v8::Value> Encode(const v8::Arguments &args);
};

#endif
Something went wrong with that request. Please try again.