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

Commit

Permalink
Added support for JWV Player
Browse files Browse the repository at this point in the history
  • Loading branch information
maxlapshin committed Nov 22, 2009
1 parent 092346f commit 7631edb
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 15 deletions.
7 changes: 6 additions & 1 deletion src/apps/apps_streaming.erl
Expand Up @@ -37,7 +37,8 @@
-author('luke@codegent.com'). -author('luke@codegent.com').
-include("../../include/ems.hrl"). -include("../../include/ems.hrl").


-export([createStream/2, play/2, deleteStream/2, closeStream/2, pause/2, pauseRaw/2, stop/2, seek/2]). -export([createStream/2, play/2, deleteStream/2, closeStream/2, pause/2, pauseRaw/2, stop/2, seek/2,
getStreamLength/2]).
-export(['WAIT_FOR_DATA'/2]). -export(['WAIT_FOR_DATA'/2]).




Expand Down Expand Up @@ -167,6 +168,10 @@ pause(AMF, #rtmp_client{video_player = Player} = State) ->
pauseRaw(AMF, State) -> pause(AMF, State). pauseRaw(AMF, State) -> pause(AMF, State).




getStreamLength(AMF, #rtmp_client{video_player = Player} = State) ->
?D({"getStreamLength", AMF}),
State.

%%------------------------------------------------------------------------- %%-------------------------------------------------------------------------
%% @spec (AMF::tuple(),Channel::tuple) -> any() %% @spec (AMF::tuple(),Channel::tuple) -> any()
%% @doc Processes a seek command and responds %% @doc Processes a seek command and responds
Expand Down
2 changes: 1 addition & 1 deletion src/ems.erl
Expand Up @@ -178,7 +178,7 @@ try_method_chain([Module | Applications], Method, Args) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------


check_app([], _Command, _Arity) -> check_app([], _Command, _Arity) ->
'apps_rtmp'; unhandled;


check_app([Module | Applications], Command, Arity) -> check_app([Module | Applications], Command, Arity) ->
case respond_to(Module, Command, Arity) of case respond_to(Module, Command, Arity) of
Expand Down
13 changes: 9 additions & 4 deletions src/ems_rtmp.erl
Expand Up @@ -227,14 +227,12 @@ command(#channel{type = Type} = Channel, State)
command(#channel{type = ?RTMP_INVOKE_AMF0} = Channel, State) -> command(#channel{type = ?RTMP_INVOKE_AMF0} = Channel, State) ->
AMF = amf0:decode(Channel#channel.msg), AMF = amf0:decode(Channel#channel.msg),
#amf{command = Command} = AMF, #amf{command = Command} = AMF,
App = ems:check_app(State,Command, 2), call_function(ems:check_app(State,Command, 2), Command, State, AMF);
App:Command(AMF, State);


command(#channel{type = ?RTMP_INVOKE_AMF3} = Channel, State) -> command(#channel{type = ?RTMP_INVOKE_AMF3} = Channel, State) ->
AMF = amf3:decode(Channel#channel.msg), AMF = amf3:decode(Channel#channel.msg),
#amf{command = Command} = AMF, #amf{command = Command} = AMF,
App = ems:check_app(State,Command, 2), call_function(ems:check_app(State,Command, 2), Command, State, AMF);
App:Command(AMF, State);


command(#channel{type = ?RTMP_TYPE_SO_AMF0, msg = Message}, State) -> command(#channel{type = ?RTMP_TYPE_SO_AMF0, msg = Message}, State) ->
decode_shared_object_amf0(Message, State); decode_shared_object_amf0(Message, State);
Expand All @@ -245,6 +243,13 @@ command(#channel{type = Type}, State) ->
?D({"Unhandled message type", Type}), ?D({"Unhandled message type", Type}),
State. State.


call_function(unhandled, Command, #rtmp_client{addr = IP, port = Port} = State, #amf{args = Args}) ->
error_logger:error_msg("Client ~p:~p requested unknown function ~p/~p", [IP, Port, Command, length(Args)]),
State;

call_function(App, Command, State, AMF) ->
App:Command(AMF, State).



decode_shared_object_amf0(<<>>, State) -> State; decode_shared_object_amf0(<<>>, State) -> State;
decode_shared_object_amf0(<<Length:16, SharedObject:Length/binary, _VersionFlags:12/binary, EventType, decode_shared_object_amf0(<<Length:16, SharedObject:Length/binary, _VersionFlags:12/binary, EventType,
Expand Down
35 changes: 27 additions & 8 deletions src/media/media_provider.erl
Expand Up @@ -101,10 +101,10 @@ handle_call({find, Name}, _From, MediaProvider) ->
{reply, find_in_cache(Name, MediaProvider), MediaProvider}; {reply, find_in_cache(Name, MediaProvider), MediaProvider};


handle_call({open, Name}, {_Opener, _Ref}, MediaProvider) -> handle_call({open, Name}, {_Opener, _Ref}, MediaProvider) ->
{reply, open_media_entry(Name, detect_type(Name), MediaProvider), MediaProvider}; {reply, open_media_entry(detect_type(Name), MediaProvider), MediaProvider};


handle_call({open, Name, Type}, {_Opener, _Ref}, MediaProvider) -> handle_call({open, Name, Type}, {_Opener, _Ref}, MediaProvider) ->
{reply, open_media_entry(Name, Type, MediaProvider), MediaProvider}; {reply, open_media_entry({Name, Type}, MediaProvider), MediaProvider};


handle_call(entries, _From, #media_provider{opened_media = OpenedMedia} = MediaProvider) -> handle_call(entries, _From, #media_provider{opened_media = OpenedMedia} = MediaProvider) ->
Entries = lists:map( Entries = lists:map(
Expand All @@ -124,7 +124,11 @@ find_in_cache(Name, #media_provider{opened_media = OpenedMedia}) ->
_ -> undefined _ -> undefined
end. end.


open_media_entry(Name, Type, #media_provider{opened_media = OpenedMedia} = MediaProvider) ->
open_media_entry({Name, notfound}, _) ->
{notfound, "No file "++Name};

open_media_entry({Name, Type}, #media_provider{opened_media = OpenedMedia} = MediaProvider) ->
case find_in_cache(Name, MediaProvider) of case find_in_cache(Name, MediaProvider) of
undefined -> undefined ->
case ems_sup:start_media(Name, Type) of case ems_sup:start_media(Name, Type) of
Expand All @@ -147,17 +151,32 @@ detect_type(Name) ->
detect_mpeg_ts(Name) -> detect_mpeg_ts(Name) ->
{ok, Re} = re:compile("http://(.*)"), {ok, Re} = re:compile("http://(.*)"),
case re:run(Name, Re) of case re:run(Name, Re) of
{match, _Captured} -> mpeg_ts; {match, _Captured} -> {Name, mpeg_ts};
_ -> detect_file(Name) _ -> detect_file(Name)
end. end.


detect_file(Name) -> detect_file(Name) ->
FileName = filename:join([file_play:file_dir(), Name]), case check_path(Name) of
case filelib:is_regular(FileName) of true -> {Name, file};
true -> file; _ -> detect_prefixed_file(Name)
_ -> live end.

detect_prefixed_file("flv:"++Name) ->
case check_path(Name) of
true -> {Name, file};
_ -> {Name, notfound}
end;

detect_prefixed_file("mp4:"++Name) ->
case check_path(Name) of
true ->
?D({"File found", Name}),
{Name, file};
_ -> {Name, notfound}
end. end.


check_path(Name) ->
filelib:is_regular(filename:join([file_play:file_dir(), Name])).


%%------------------------------------------------------------------------- %%-------------------------------------------------------------------------
%% @spec (Msg, State) ->{noreply, State} | %% @spec (Msg, State) ->{noreply, State} |
Expand Down
6 changes: 5 additions & 1 deletion wwwroot/index.html
Expand Up @@ -18,7 +18,11 @@
} }
</script> </script>
<div class="container"> <div class="container">
<div class="span-24 last"><h3 style="float: left; margin-right: 2em"><a href="/admin">Admin</a></h3> <h3 style="float: left; margin-right: 2em"><a href="/chat.html">Chat</a></h3></div> <div class="span-24 last">
<h3 style="float: left; margin-right: 2em"><a href="/admin">Admin</a></h3>
<h3 style="float: left; margin-right: 2em"><a href="/chat.html">Chat</a></h3>
<h3 style="float: left; margin-right: 2em"><a href="/longtail/index.html">JWV Player</a></h3>
</div>


<div class="span-16"> <div class="span-16">
<object width="600" height="620" type="application/x-shockwave-flash" id="flash-program-player" name="flash-program-player" data="player/Player.swf"> <object width="600" height="620" type="application/x-shockwave-flash" id="flash-program-player" name="flash-program-player" data="player/Player.swf">
Expand Down

0 comments on commit 7631edb

Please sign in to comment.