Permalink
Browse files

Admin page with clients

  • Loading branch information...
1 parent ad13f29 commit 670ecec67a7ad026649e02002143a719f0236d67 @maxlapshin maxlapshin committed Nov 22, 2009
Showing with 47 additions and 12 deletions.
  1. +2 −2 src/ems_http.erl
  2. +2 −2 src/formats/mp4.erl
  3. +5 −0 src/media/file_media.erl
  4. +16 −3 src/media/file_play.erl
  5. +11 −1 src/media/media_provider.erl
  6. +3 −2 src/rtmp_client.erl
  7. +8 −2 wwwroot/admin.html
View
@@ -41,9 +41,9 @@ handle('GET', ["admin"], Req) ->
erlydtl:compile("wwwroot/admin.html", admin_template),
% {ok, Contents} = file:read_file("player/player.html"),
- FileList = [],
+ Entries = media_provider:entries(),
{ok, Index} = admin_template:render([
- {files, FileList}]),
+ {entries, Entries}]),
Req:ok([{'Content-Type', "text/html; charset=utf8"}], Index);
View
@@ -45,7 +45,7 @@
codec_config(video, MediaInfo) ->
Config = decoder_config(video, MediaInfo),
- ?D({"Video config", Config}),
+ % ?D({"Video config", Config}),
#video_frame{
type = ?FLV_TAG_TYPE_VIDEO,
decoder_config = true,
@@ -59,7 +59,7 @@ codec_config(video, MediaInfo) ->
codec_config(audio, MediaInfo) ->
Config = decoder_config(audio, MediaInfo),
- ?D({"Audio config", Config}),
+ % ?D({"Audio config", Config}),
#video_frame{
type = ?FLV_TAG_TYPE_AUDIO,
decoder_config = true,
View
@@ -63,6 +63,11 @@ handle_call({create_player, Options}, _From, #media_info{file_name = Name, clien
?D({"Creating media player for", Name, "client", proplists:get_value(consumer, Options)}),
{reply, {ok, Pid}, MediaInfo};
+handle_call(clients, _From, #media_info{clients = Clients} = MediaInfo) ->
+ Entries = lists:map(
+ fun([Pid]) -> file_play:client(Pid) end,
+ ets:match(Clients, {'$1'})),
+ {reply, Entries, MediaInfo};
handle_call({codec_config, Type}, _From, #media_info{format = FileFormat} = MediaInfo) ->
{reply, FileFormat:codec_config(Type, MediaInfo), MediaInfo};
View
@@ -39,7 +39,7 @@
-include("../../include/ems.hrl").
--export([file_dir/0, file_format/1, start/1, start/2]).
+-export([file_dir/0, file_format/1, start/1, start/2, client/1]).
-export([init/2, ready/1]).
@@ -68,6 +68,15 @@ start(MediaEntry) -> start(MediaEntry, []).
start(MediaEntry, Options) ->
{ok, spawn_link(?MODULE, init, [MediaEntry, Options])}.
+
+client(Player) ->
+ Ref = erlang:make_ref(),
+ Player ! {client, self(), Ref},
+ receive
+ {Info, Ref} -> Info
+ after 10 ->
+ {undefined, undefined}
+ end.
init(MediaEntry, Options) ->
@@ -96,6 +105,10 @@ ready(#file_player{media_info = MediaInfo,
?D({"Player starting with pid", self(), MediaInfo}),
?MODULE:ready(State#file_player{prepush = ClientBuffer, paused = false});
+ {client, Pid, Ref} ->
+ Pid ! {gen_fsm:sync_send_event(Consumer, info), Ref},
+ ?MODULE:ready(State);
+
pause ->
?D("Player paused"),
timer:cancel(Timer),
@@ -140,11 +153,11 @@ play(#file_player{paused = true} = State) ->
play(#file_player{sent_audio_config = false, media_info = MediaInfo} = Player) ->
- ?D({"Sent audio config"}),
+ % ?D({"Sent audio config"}),
send_frame(Player#file_player{sent_audio_config = true}, {ok, file_media:codec_config(MediaInfo, audio)});
play(#file_player{sent_video_config = false, media_info = MediaInfo} = Player) ->
- ?D({"Sent video config"}),
+ % ?D({"Sent video config"}),
send_frame(Player#file_player{sent_video_config = true}, {ok, file_media:codec_config(MediaInfo, video)});
@@ -8,7 +8,7 @@
-behaviour(gen_server).
%% External API
--export([start_link/0, create/2, play/1, play/2]).
+-export([start_link/0, create/2, play/1, play/2, entries/0]).
%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
@@ -41,6 +41,9 @@ open(Name, Type) ->
find(Name) ->
gen_server:call(?MODULE, {find, Name}).
+
+entries() ->
+ gen_server:call(?MODULE, entries).
% Plays media with default options
@@ -103,6 +106,13 @@ handle_call({open, Name}, {_Opener, _Ref}, MediaProvider) ->
handle_call({open, Name, Type}, {_Opener, _Ref}, MediaProvider) ->
{reply, open_media_entry(Name, Type, MediaProvider), MediaProvider};
+handle_call(entries, _From, #media_provider{opened_media = OpenedMedia} = MediaProvider) ->
+ Entries = lists:map(
+ fun([Name, Handler]) ->
+ {Name, gen_server:call(Handler, clients)}
+ end,
+ ets:match(OpenedMedia, {'_', '$1', '$2'})),
+ {reply, Entries, MediaProvider};
handle_call(Request, _From, State) ->
{stop, {unknown_call, Request}, State}.
View
@@ -195,8 +195,8 @@ init([]) ->
Reply -> Reply
end.
-'WAIT_FOR_DATA'({info}, _From, #rtmp_client{addr = Address, port = Port} = State) ->
- {reply, [{ip, Address, Port}], 'WAIT_FOR_DATA', State, ?TIMEOUT};
+'WAIT_FOR_DATA'(info, _From, #rtmp_client{addr = {IP1, IP2, IP3, IP4}, port = Port} = State) ->
+ {reply, {io_lib:format("~p.~p.~p.~p", [IP1, IP2, IP3, IP4]), Port}, 'WAIT_FOR_DATA', State, ?TIMEOUT};
'WAIT_FOR_DATA'(Data, _From, State) ->
@@ -225,6 +225,7 @@ handle_event(Event, StateName, StateData) ->
%% {stop, Reason, Reply, NewStateData}
%% @private
%%-------------------------------------------------------------------------
+
handle_sync_event(Event, _From, StateName, StateData) ->
io:format("TRACE ~p:~p ~p~n",[?MODULE, ?LINE, got_sync_request2]),
{stop, {StateName, undefined_event, Event}, StateData}.
View
@@ -16,8 +16,14 @@
<div class="span-24 last">
<ul>
- {% for file in files %}
- <li><a href="?file={{file}}&autostart=true">{{file}}</a></li>
+ {% for name, clients in entries %}
+ <li><a href="?file={{name}}&autostart=true">{{name}}</a>
+ <ul>
+ {% for addr, port in clients %}
+ <li>{{addr}}:{{port}}</li>
+ {% endfor %}
+ </ul>
+ </li>
{% endfor %}
</ul>

0 comments on commit 670ecec

Please sign in to comment.