Permalink
Browse files

Done huge refactoring of media provider file playing

  • Loading branch information...
1 parent c2a26e1 commit 096ef127b1f174bea7e5d2a0e4872aa551aee3b0 @maxlapshin maxlapshin committed Nov 21, 2009
Showing with 14 additions and 17 deletions.
  1. +2 −2 src/formats/mp4.erl
  2. +12 −15 src/media/file_play.erl
View
@@ -54,7 +54,7 @@ codec_config(video, MediaInfo) ->
frame_type = ?FLV_VIDEO_FRAME_TYPE_KEYFRAME,
codec_id = ?FLV_VIDEO_CODEC_AVC,
raw_body = false,
- nextpos = 0
+ nextpos = undefined
};
codec_config(audio, MediaInfo) ->
@@ -70,7 +70,7 @@ codec_config(audio, MediaInfo) ->
sound_size = ?FLV_AUDIO_SIZE_16BIT,
sound_rate = ?FLV_AUDIO_RATE_44,
raw_body = false,
- nextpos = 0
+ nextpos = undefined
}.
View
@@ -139,15 +139,13 @@ play(#file_player{paused = true} = State) ->
?MODULE:ready(State);
-play(#file_player{sent_audio_config = false, media_info = MediaInfo, consumer = Consumer} = State) ->
- ems_play:send(Consumer, file_media:codec_config(MediaInfo, audio)),
+play(#file_player{sent_audio_config = false, media_info = MediaInfo} = Player) ->
?D({"Sent audio config"}),
- play(State#file_player{sent_audio_config = true});
+ 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, consumer = Consumer} = State) ->
- ems_play:send(Consumer, file_media:codec_config(MediaInfo, video)),
+play(#file_player{sent_video_config = false, media_info = MediaInfo} = Player) ->
?D({"Sent video config"}),
- play(State#file_player{sent_video_config = true});
+ send_frame(Player#file_player{sent_video_config = true}, {ok, file_media:codec_config(MediaInfo, video)});
play(#file_player{media_info = MediaInfo, pos = Key} = Player) ->
@@ -162,12 +160,9 @@ send_frame(#file_player{consumer = Consumer, stream_id = StreamId} = Player, {ok
% ?D({"Frame", Key, Frame#video_frame.timestamp_abs, NextPos}),
TimeStamp = Frame#video_frame.timestamp_abs - Player#file_player.ts_prev,
ems_play:send(Consumer, Frame#video_frame{timestamp=TimeStamp, streamid = StreamId}),
- {Timeout, Player1} = timeout(Frame, Player),
+ Player1 = timeout_play(Frame, Player),
% ?D({"Frame", Consumer, Frame#video_frame.timestamp_abs, Player#file_player.timer_start, TimeStamp, Timeout}),
- NextState = Player1#file_player{
- timer_ref = timer:send_after(Timeout, play),
- ts_prev = Frame#video_frame.timestamp_abs,
- pos = NextPos},
+ NextState = Player1#file_player{ts_prev = Frame#video_frame.timestamp_abs, pos = NextPos},
% {_, Sec2, MSec2} = erlang:now(),
% _Delta = (Sec2*1000 + MSec2) - (Sec1*1000 + MSec1),
% ?D({"Read frame", Delta}),
@@ -204,17 +199,19 @@ file_format(Name) ->
%% @end
%%-------------------------------------------------------------------------
-timeout(#video_frame{timestamp_abs = AbsTime}, #file_player{timer_start = TimerStart, client_buffer = ClientBuffer, playing_from = PlayingFrom, prepush = Prepush} = Player) ->
+timeout_play(#video_frame{timestamp_abs = AbsTime}, #file_player{timer_start = TimerStart, client_buffer = ClientBuffer, playing_from = PlayingFrom, prepush = Prepush} = Player) ->
SeekTime = AbsTime - PlayingFrom,
Timeout = SeekTime - ClientBuffer - trunc(timer:now_diff(now(), TimerStart) / 1000),
% ?D({"Timeout", Timeout, SeekTime, ClientBuffer, trunc(timer:now_diff(now(), TimerStart) / 1000)}),
if
(Prepush > SeekTime) ->
- {0, Player#file_player{prepush = Prepush - SeekTime}};
+ self() ! play,
+ Player#file_player{prepush = Prepush - SeekTime};
(Timeout > 0) ->
- {Timeout, Player};
+ Player#file_player{timer_ref = timer:send_after(Timeout, play)};
true ->
- {0, Player}
+ self() ! play,
+ Player
end.

0 comments on commit 096ef12

Please sign in to comment.