Skip to content
Browse files

Back working everything after refactoring

  • Loading branch information...
1 parent 11b662b commit 7b25b107d76013a76c6924281cb2d3a0b93e150c @maxlapshin maxlapshin committed
Showing with 22 additions and 9 deletions.
  1. +2 −2 src/apps/apps_recording.erl
  2. +1 −0 src/ems_sup.erl
  3. +2 −2 src/media/file_media.erl
  4. +4 −0 src/media/file_play.erl
  5. +13 −5 src/media/media_provider.erl
View
4 src/apps/apps_recording.erl
@@ -46,7 +46,7 @@
'WAIT_FOR_DATA'({publish, #channel{} = Channel}, #rtmp_client{video_player = Recorder} = State) ->
- media_entry:publish(Recorder, Channel),
+ stream_media:publish(Recorder, Channel),
{next_state, 'WAIT_FOR_DATA', State, ?TIMEOUT};
@@ -85,6 +85,7 @@
publish(#amf{args = [{null,null},{string,Name},{string,"record"}]} = _AMF, State) ->
?D({"Publish - Action - record",Name}),
Recorder = media_provider:create(Name, record),
+ ?D({"Recording", Recorder}),
State#rtmp_client{video_player = Recorder, video_state = publishing};
@@ -97,7 +98,6 @@ publish(#amf{args = [{null,null},{string,Name},{string,"append"}]} = _AMF, State
publish(#amf{args = [{null,null},{string,Name},{string,"live"}]} = _AMF, State) ->
?D({"Publish - Action - live",Name}),
Recorder = media_provider:create(Name, live),
- media_entry:subscribe(Recorder, self()),
State#rtmp_client{video_player = Recorder, video_state = publishing};
publish(#amf{args = [{null,null},{string,Name}]} = _AMF, State) ->
View
1 src/ems_sup.erl
@@ -72,6 +72,7 @@ start_rtsp_client() -> supervisor:start_child(rtsp_client_sup, []).
%%--------------------------------------------------------------------
start_media(Name, file = Type) -> supervisor:start_child(file_media_sup, [Name, Type]);
start_media(Name, mpeg_ts = Type) -> supervisor:start_child(stream_media_sup, [Name, Type]);
+start_media(Name, record = Type) -> supervisor:start_child(stream_media_sup, [Name, Type]);
start_media(Name, live = Type) -> supervisor:start_child(stream_media_sup, [Name, Type]).
%%--------------------------------------------------------------------
View
4 src/media/file_media.erl
@@ -140,9 +140,9 @@ handle_info({'EXIT', Owner, _Reason}, #media_info{owner = Owner, clients = Clien
end,
{noreply, MediaInfo#media_info{owner = Owner}};
-handle_info({'EXIT', Client, _Reason}, #media_info{clients = Clients} = MediaInfo) ->
+handle_info({'EXIT', Client, _Reason}, #media_info{clients = Clients, file_name = FileName} = MediaInfo) ->
ets:delete(Clients, Client),
- ?D({"Removing client", Client, "left", ets:info(Clients, size)}),
+ ?D({"Removing client of", FileName, Client, "left", ets:info(Clients, size)}),
case ets:info(Clients, size) of
0 -> timer:send_after(?FILE_CACHE_TIME, {graceful});
_ -> ok
View
4 src/media/file_play.erl
@@ -150,6 +150,10 @@ play(#file_player{sent_video_config = false, media_info = MediaInfo} = Player) -
play(#file_player{media_info = MediaInfo, pos = Key} = Player) ->
send_frame(Player, file_media:read_frame(MediaInfo, Key)).
+
+send_frame(Player, {ok, undefined}) ->
+ self() ! play,
+ ?MODULE:ready(Player);
send_frame(#file_player{consumer = Consumer} = Player, {ok, done}) ->
?D("Video file finished"),
View
18 src/media/media_provider.erl
@@ -29,11 +29,16 @@ start_link() ->
create(Name, Type) ->
?D({"Create", Name, Type}),
- gen_server:call(?MODULE, {create, Name}).
+ Pid = open(Name, Type),
+ stream_media:set_owner(Pid, self()),
+ Pid.
open(Name) ->
gen_server:call(?MODULE, {open, Name}).
+open(Name, Type) ->
+ gen_server:call(?MODULE, {open, Name, Type}).
+
find(Name) ->
gen_server:call(?MODULE, {find, Name}).
@@ -93,10 +98,14 @@ handle_call({find, Name}, _From, MediaProvider) ->
{reply, find_in_cache(Name, MediaProvider), MediaProvider};
handle_call({open, Name}, {_Opener, _Ref}, MediaProvider) ->
- {reply, open_media_entry(Name, MediaProvider), MediaProvider};
+ {reply, open_media_entry(Name, detect_type(Name), MediaProvider), MediaProvider};
+
+handle_call({open, Name, Type}, {_Opener, _Ref}, MediaProvider) ->
+ {reply, open_media_entry(Name, Type, MediaProvider), MediaProvider};
+
handle_call(Request, _From, State) ->
- {stop, {unknown_call, Request}, State}.
+ {stop, {unknown_call, Request}, State}.
find_in_cache(Name, #media_provider{opened_media = OpenedMedia}) ->
@@ -105,10 +114,9 @@ find_in_cache(Name, #media_provider{opened_media = OpenedMedia}) ->
_ -> undefined
end.
-open_media_entry(Name, #media_provider{opened_media = OpenedMedia} = MediaProvider) ->
+open_media_entry(Name, Type, #media_provider{opened_media = OpenedMedia} = MediaProvider) ->
case find_in_cache(Name, MediaProvider) of
undefined ->
- Type = detect_type(Name),
case ems_sup:start_media(Name, Type) of
{ok, Pid} ->
link(Pid),

0 comments on commit 7b25b10

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