Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added support for JWV Player

  • Loading branch information...
commit 7631edbb97184be402ca6b94df2377cc8a739ab5 1 parent 092346f
Max Lapshin maxlapshin authored
7 src/apps/apps_streaming.erl
@@ -37,7 +37,8 @@
37 37 -author('luke@codegent.com').
38 38 -include("../../include/ems.hrl").
39 39
40   --export([createStream/2, play/2, deleteStream/2, closeStream/2, pause/2, pauseRaw/2, stop/2, seek/2]).
  40 +-export([createStream/2, play/2, deleteStream/2, closeStream/2, pause/2, pauseRaw/2, stop/2, seek/2,
  41 + getStreamLength/2]).
41 42 -export(['WAIT_FOR_DATA'/2]).
42 43
43 44
@@ -167,6 +168,10 @@ pause(AMF, #rtmp_client{video_player = Player} = State) ->
167 168 pauseRaw(AMF, State) -> pause(AMF, State).
168 169
169 170
  171 +getStreamLength(AMF, #rtmp_client{video_player = Player} = State) ->
  172 + ?D({"getStreamLength", AMF}),
  173 + State.
  174 +
170 175 %%-------------------------------------------------------------------------
171 176 %% @spec (AMF::tuple(),Channel::tuple) -> any()
172 177 %% @doc Processes a seek command and responds
2  src/ems.erl
@@ -178,7 +178,7 @@ try_method_chain([Module | Applications], Method, Args) ->
178 178 %%--------------------------------------------------------------------
179 179
180 180 check_app([], _Command, _Arity) ->
181   - 'apps_rtmp';
  181 + unhandled;
182 182
183 183 check_app([Module | Applications], Command, Arity) ->
184 184 case respond_to(Module, Command, Arity) of
13 src/ems_rtmp.erl
@@ -227,14 +227,12 @@ command(#channel{type = Type} = Channel, State)
227 227 command(#channel{type = ?RTMP_INVOKE_AMF0} = Channel, State) ->
228 228 AMF = amf0:decode(Channel#channel.msg),
229 229 #amf{command = Command} = AMF,
230   - App = ems:check_app(State,Command, 2),
231   - App:Command(AMF, State);
  230 + call_function(ems:check_app(State,Command, 2), Command, State, AMF);
232 231
233 232 command(#channel{type = ?RTMP_INVOKE_AMF3} = Channel, State) ->
234 233 AMF = amf3:decode(Channel#channel.msg),
235 234 #amf{command = Command} = AMF,
236   - App = ems:check_app(State,Command, 2),
237   - App:Command(AMF, State);
  235 + call_function(ems:check_app(State,Command, 2), Command, State, AMF);
238 236
239 237 command(#channel{type = ?RTMP_TYPE_SO_AMF0, msg = Message}, State) ->
240 238 decode_shared_object_amf0(Message, State);
@@ -245,6 +243,13 @@ command(#channel{type = Type}, State) ->
245 243 ?D({"Unhandled message type", Type}),
246 244 State.
247 245
  246 +call_function(unhandled, Command, #rtmp_client{addr = IP, port = Port} = State, #amf{args = Args}) ->
  247 + error_logger:error_msg("Client ~p:~p requested unknown function ~p/~p", [IP, Port, Command, length(Args)]),
  248 + State;
  249 +
  250 +call_function(App, Command, State, AMF) ->
  251 + App:Command(AMF, State).
  252 +
248 253
249 254 decode_shared_object_amf0(<<>>, State) -> State;
250 255 decode_shared_object_amf0(<<Length:16, SharedObject:Length/binary, _VersionFlags:12/binary, EventType,
35 src/media/media_provider.erl
@@ -101,10 +101,10 @@ handle_call({find, Name}, _From, MediaProvider) ->
101 101 {reply, find_in_cache(Name, MediaProvider), MediaProvider};
102 102
103 103 handle_call({open, Name}, {_Opener, _Ref}, MediaProvider) ->
104   - {reply, open_media_entry(Name, detect_type(Name), MediaProvider), MediaProvider};
  104 + {reply, open_media_entry(detect_type(Name), MediaProvider), MediaProvider};
105 105
106 106 handle_call({open, Name, Type}, {_Opener, _Ref}, MediaProvider) ->
107   - {reply, open_media_entry(Name, Type, MediaProvider), MediaProvider};
  107 + {reply, open_media_entry({Name, Type}, MediaProvider), MediaProvider};
108 108
109 109 handle_call(entries, _From, #media_provider{opened_media = OpenedMedia} = MediaProvider) ->
110 110 Entries = lists:map(
@@ -124,7 +124,11 @@ find_in_cache(Name, #media_provider{opened_media = OpenedMedia}) ->
124 124 _ -> undefined
125 125 end.
126 126
127   -open_media_entry(Name, Type, #media_provider{opened_media = OpenedMedia} = MediaProvider) ->
  127 +
  128 +open_media_entry({Name, notfound}, _) ->
  129 + {notfound, "No file "++Name};
  130 +
  131 +open_media_entry({Name, Type}, #media_provider{opened_media = OpenedMedia} = MediaProvider) ->
128 132 case find_in_cache(Name, MediaProvider) of
129 133 undefined ->
130 134 case ems_sup:start_media(Name, Type) of
@@ -147,17 +151,32 @@ detect_type(Name) ->
147 151 detect_mpeg_ts(Name) ->
148 152 {ok, Re} = re:compile("http://(.*)"),
149 153 case re:run(Name, Re) of
150   - {match, _Captured} -> mpeg_ts;
  154 + {match, _Captured} -> {Name, mpeg_ts};
151 155 _ -> detect_file(Name)
152 156 end.
153 157
154 158 detect_file(Name) ->
155   - FileName = filename:join([file_play:file_dir(), Name]),
156   - case filelib:is_regular(FileName) of
157   - true -> file;
158   - _ -> live
  159 + case check_path(Name) of
  160 + true -> {Name, file};
  161 + _ -> detect_prefixed_file(Name)
  162 + end.
  163 +
  164 +detect_prefixed_file("flv:"++Name) ->
  165 + case check_path(Name) of
  166 + true -> {Name, file};
  167 + _ -> {Name, notfound}
  168 + end;
  169 +
  170 +detect_prefixed_file("mp4:"++Name) ->
  171 + case check_path(Name) of
  172 + true ->
  173 + ?D({"File found", Name}),
  174 + {Name, file};
  175 + _ -> {Name, notfound}
159 176 end.
160 177
  178 +check_path(Name) ->
  179 + filelib:is_regular(filename:join([file_play:file_dir(), Name])).
161 180
162 181 %%-------------------------------------------------------------------------
163 182 %% @spec (Msg, State) ->{noreply, State} |
6 wwwroot/index.html
@@ -18,7 +18,11 @@
18 18 }
19 19 </script>
20 20 <div class="container">
21   - <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>
  21 + <div class="span-24 last">
  22 + <h3 style="float: left; margin-right: 2em"><a href="/admin">Admin</a></h3>
  23 + <h3 style="float: left; margin-right: 2em"><a href="/chat.html">Chat</a></h3>
  24 + <h3 style="float: left; margin-right: 2em"><a href="/longtail/index.html">JWV Player</a></h3>
  25 + </div>
22 26
23 27 <div class="span-16">
24 28 <object width="600" height="620" type="application/x-shockwave-flash" id="flash-program-player" name="flash-program-player" data="player/Player.swf">

0 comments on commit 7631edb

Please sign in to comment.
Something went wrong with that request. Please try again.