Skip to content

Commit

Permalink
Merge pull request #2 from opencubeware/overlay
Browse files Browse the repository at this point in the history
Standalone device
  • Loading branch information
studzien committed Mar 31, 2014
2 parents e0e499d + d2f51d9 commit fc1961e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
17 changes: 11 additions & 6 deletions c_src/chat_camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

#include "chat.h"

#include <errno.h>


#define MMAL_CAMERA_PREVIEW_PORT 0
#define MMAL_CAMERA_VIDEO_PORT 1
Expand Down Expand Up @@ -282,11 +284,14 @@ int setup_camera(PORT_USERDATA *userdata) {
fill_port_buffer(userdata->camera_video_port, userdata->camera_video_port_pool);


MMAL_PARAMETER_MIRROR_T mirror = {{MMAL_PARAMETER_MIRROR, sizeof(MMAL_PARAMETER_MIRROR_T)}, MMAL_PARAM_MIRROR_NONE};
mirror.value = MMAL_PARAM_MIRROR_BOTH;
mmal_port_parameter_set(camera->output[0], &mirror.hdr);
mmal_port_parameter_set(camera->output[1], &mirror.hdr);
mmal_port_parameter_set(camera->output[2], &mirror.hdr);
/*MMAL_PARAMETER_MIRROR_T mirror = {{MMAL_PARAMETER_MIRROR, sizeof(MMAL_PARAMETER_MIRROR_T)}, MMAL_PARAM_MIRROR_NONE};*/
/*mirror.value = MMAL_PARAM_MIRROR_BOTH;*/
/*mmal_port_parameter_set(camera->output[0], &mirror.hdr);*/
/*mmal_port_parameter_set(camera->output[1], &mirror.hdr);*/
/*mmal_port_parameter_set(camera->output[2], &mirror.hdr);*/
mmal_port_parameter_set_int32(camera->output[0], MMAL_PARAMETER_ROTATION, 90);
mmal_port_parameter_set_int32(camera->output[1], MMAL_PARAMETER_ROTATION, 90);
mmal_port_parameter_set_int32(camera->output[2], MMAL_PARAMETER_ROTATION, 90);

if (mmal_port_parameter_set_boolean(camera_video_port, MMAL_PARAMETER_CAPTURE, 1) != MMAL_SUCCESS) {
//printf("%s: Failed to start capture\n", __func__);
Expand Down Expand Up @@ -473,7 +478,7 @@ int main(int argc, char** argv) {

data_attr.mq_msgsize = DATASIZE;
data_attr.mq_flags = 0;
data_attr.mq_maxmsg = 10;
data_attr.mq_maxmsg = 2;
data_attr.mq_curmsgs = 0;
reader = mq_open(DATA_QUEUE, O_RDONLY | O_CREAT | O_NONBLOCK, PERMS, &data_attr);

Expand Down
21 changes: 19 additions & 2 deletions c_src/chat_overlay.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
#include "chat_overlay.h"

#include <errno.h>
#include <sys/resource.h>

static int load(ErlNifEnv* env, void** priv_data, ERL_NIF_TERM load_info) {
// set limits for POSIX queue size
struct rlimit limits;
limits.rlim_cur = (rlim_t)(4*DATASIZE);
limits.rlim_max = (rlim_t)(4*DATASIZE);
setrlimit(RLIMIT_MSGQUEUE, &limits);

// build local environment
local_env = enif_alloc_env();

Expand All @@ -27,8 +34,18 @@ static int load(ErlNifEnv* env, void** priv_data, ERL_NIF_TERM load_info) {
reader = mq_open(WORKER_QUEUE, O_RDONLY);
data_writer = mq_open(DATA_QUEUE, O_CREAT | O_WRONLY | O_NONBLOCK, PERMS, &data_attr);

if(writer == -1 || reader == -1 || data_writer == -1) {
perror("chat_overlay NIF loading error: ");
if(writer == -1) {
perror("chat_overlay NIF loading error (writer queue): ");
return 1;
}

if(reader == -1) {
perror("chat_overlay NIF loading error (reader queue): ");
return 1;
}

if(data_writer == -1) {
perror("chat_overlay NIF loading error (data_writer queue): ");
return 1;
}

Expand Down
8 changes: 7 additions & 1 deletion src/chat_camera.erl
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,18 @@ code_change(_OldVsn, State, _Extra) ->
%%%===================================================================
%%% Internal functions
%%%===================================================================
cmd(Bitrate, {yt, List}) when is_list(List) ->
app(Bitrate) ++ " | " ++
"ffmpeg -ar 44100 -f s16le -ac 2 -i /dev/zero -i - -vcodec copy "
"-acodec aac -ab 128k -f flv -strict experimental -shortest "
++ List ++ " 2> /dev/null";
cmd(Bitrate, {rtmp, List}) when is_list(List) ->
app(Bitrate) ++ " | " ++
"ffmpeg -i - -vcodec copy -an -f flv " ++ List ++ " 2> /dev/null";
cmd(Bitrate, Other) ->
app(Bitrate) ++ " > " ++ Other.

app(Bitrate) ->
filename:join([priv, lib, chat_camera]) ++ " " ++ integer_to_list(Bitrate).
filename:join([priv, lib, chat_camera]) ++ " " ++
integer_to_list(Bitrate).

2 changes: 1 addition & 1 deletion src/chat_remote.erl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ code_change(_OldVsn, State, _Extra) ->
%%%===================================================================
handle_preview() ->
Cmd = lists:concat(["raspistill -w 640 -h 480 "
" -q 100 -t 1 -vf -hf -o -"]),
" -q 100 -t 1 -rot 90 -o -"]),
Port = erlang:open_port({spawn, Cmd}, [binary, exit_status]),
capture_preview(<<>>, Port).

Expand Down

0 comments on commit fc1961e

Please sign in to comment.