Skip to content
This repository has been archived by the owner on Feb 21, 2020. It is now read-only.

Commit

Permalink
fixed reading netstream and filedir
Browse files Browse the repository at this point in the history
  • Loading branch information
maxlapshin committed Oct 1, 2009
1 parent c73c3be commit d33cdb6
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 46 deletions.
37 changes: 36 additions & 1 deletion src/ems.erl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
-include("../include/ems.hrl").

-export([start/0,stop/0,restart/0,rebuild/0,reload/0]).
-export ([get_var/1,get_var/2]).


%%--------------------------------------------------------------------
Expand Down Expand Up @@ -104,4 +105,38 @@ reload([?MODULE | T]) -> reload(T);
reload([H|T]) ->
reload(H),
reload(H),
reload(T).
reload(T).




%%--------------------------------------------------------------------
%% @spec (Opt::atom()) -> any()
%% @doc Gets application enviroment variable. User defined varaibles in
%% .config file override application default varabiles. Default [].
%% @end
%%--------------------------------------------------------------------
get_var(Opt) -> get_var(Opt, []).
%%--------------------------------------------------------------------
%% @spec (Opt::atom(), Default::any()) -> any()
%% @doc Gets application enviroment variable. Returns Default if no
%% varaible named Opt is found. User defined varaibles in .config file
%% override application default varabiles.
%% @end
%%--------------------------------------------------------------------
get_var(Opt, Default) ->
case lists:keysearch(?APPLICATION, 1, application:loaded_applications()) of
false -> application:load(?APPLICATION);
_ -> ok
end,
case application:get_env(?APPLICATION, Opt) of
{ok, Val} -> Val;
_ ->
case init:get_argument(Opt) of
[[Val | _]] -> Val;
error -> Default
end
end.



3 changes: 3 additions & 0 deletions src/ems_fsm.erl
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ init([]) ->
NextState = State#ems_fsm{type = vod, video_player = PlayerPid},
gen_fsm:send_event(PlayerPid, {start}),
{next_state, 'WAIT_FOR_DATA', NextState, ?TIMEOUT};
{notfound} ->
gen_fsm:send_event(self(), {status, ?NS_PLAY_STREAM_NOT_FOUND, 1}),
{next_state, 'WAIT_FOR_DATA', State, ?TIMEOUT};
Reason ->
?D({"Failed to start video player", Reason}),
{error, Reason}
Expand Down
19 changes: 13 additions & 6 deletions src/ems_play.erl
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,25 @@ play(Name, StreamId, _) ->
true ->
init_file(FileName, StreamId);
_ ->
init_stream(Name, StreamId)
case ems:get_var(netstream, undefined) of
undefined -> {notfound};
_ -> init_stream(Name, StreamId)
end
end.


init_file(FileName, StreamId) ->
gen_fsm:start_link(?MODULE, {FileName, StreamId, self()}, []).

init_stream(Name, StreamId) ->
{ok, NetStream} = rpc:call('netstream@lmax.local', rtmp, start, [Name], ?TIMEOUT),
link(NetStream),
?D({"Netstream created", NetStream}),
{ok, NetStream}.
case rpc:call('netstream@lmax.local', rtmp, start, [Name], ?TIMEOUT) of
{ok, NetStream} ->
link(NetStream),
?D({"Netstream created", NetStream}),
{ok, NetStream};
_ ->
{notfound}
end.


init({FileName, StreamId, Parent}) ->
Expand Down Expand Up @@ -174,7 +181,7 @@ channel_id(?FLV_TAG_TYPE_AUDIO, _StreamId) -> 5.
%% @end
%%-------------------------------------------------------------------------
file_dir() ->
ems_sup:get_app_env(file_dir, "/tmp").
ems:get_var(file_dir, "/tmp").



Expand Down
2 changes: 1 addition & 1 deletion src/ems_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ start_link(Port, Module) when is_integer(Port), is_atom(Module) ->
%%----------------------------------------------------------------------
init([Port, Module]) ->
process_flag(trap_exit, true),
error_logger:info_msg("Starting with file directory ~p~n", [ems_sup:get_app_env(file_dir, "/tmp")]),
error_logger:info_msg("Starting with file directory ~p~n", [ems:get_var(file_dir, "/tmp")]),
Opts = [binary, {packet, raw}, {reuseaddr, true},
{keepalive, true}, {backlog, 30}, {active, false}],
case gen_tcp:listen(Port, Opts) of
Expand Down
30 changes: 1 addition & 29 deletions src/ems_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@

-export ([init/1,start_link/0]).
-export ([start_client/0]).
-export ([get_app_env/1,get_app_env/2]).

start_link() ->
ListenPort = get_app_env(listen_port, ?RTMP_PORT),
ListenPort = ems:get_var(listen_port, ?RTMP_PORT),
supervisor:start_link({local, ?MODULE}, ?MODULE, [ListenPort]).


Expand Down Expand Up @@ -112,30 +111,3 @@ start_client() -> supervisor:start_child(ems_client_sup, []).



%%--------------------------------------------------------------------
%% @spec (Opt::atom()) -> any()
%% @doc Gets application enviroment variable. User defined varaibles in
%% .config file override application default varabiles. Default [].
%% @end
%%--------------------------------------------------------------------
get_app_env(Opt) -> get_app_env(Opt, []).
%%--------------------------------------------------------------------
%% @spec (Opt::atom(), Default::any()) -> any()
%% @doc Gets application enviroment variable. Returns Default if no
%% varaible named Opt is found. User defined varaibles in .config file
%% override application default varabiles.
%% @end
%%--------------------------------------------------------------------
get_app_env(Opt, Default) ->
case lists:keysearch(?APPLICATION, 1, application:loaded_applications()) of
false -> application:load(?APPLICATION);
_ -> ok
end,
case application:get_env(?APPLICATION, Opt) of
{ok, Val} -> Val;
_ ->
case init:get_argument(Opt) of
[[Val | _]] -> Val;
error -> Default
end
end.
20 changes: 11 additions & 9 deletions src/erlmedia.app
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,30 @@
{vsn, "0.0.6"},
{id, "erlmedia"},
{modules, [
ems,
ems,
ems_amf,
ems_app,
ems_demo,
ems_flv,
ems_mp4,
ems_play,
ems_cluster,
ems_flv,
ems_fsm,
ems_proxy,
ems_play,
ems_rtmp,
ems_server,
ems_sup,
ems_test,
gen_rtmp
gen_rtmp,
gen_server_cluster,
hmac256,
mp4,
rtmp_handshake,
sha2
]},
{registered, []},
{applications, [kernel, stdlib]},
{mod, {ems_app, []}},
{env, [
{listen_port, 1935},
{flv_dir, "/tmp"}
{file_dir, "/tmp"},
{netstream, "netstream@localhost"}
]}
]
}.
Expand Down

0 comments on commit d33cdb6

Please sign in to comment.