Permalink
Browse files

Fixing issue with invalid audio timestamps

  • Loading branch information...
maxlapshin committed Nov 23, 2009
1 parent 5884148 commit 76bc923ef28a02d828931004c1786d39a622c45a
Showing with 29 additions and 28 deletions.
  1. +2 −2 src/apps/apps_recording.erl
  2. +5 −6 src/ems_flv.erl
  3. +0 −2 src/formats/mp4.erl
  4. +14 −10 src/media/stream_media.erl
  5. +8 −8 src/rtmp.erl
@@ -102,6 +102,6 @@ publish(#amf{args = [{null,null},{string,Name},{string,"live"}]} = _AMF, State)
publish(#amf{args = [{null,null},{string,Name}]} = _AMF, State) ->
?D({"Publish - Action - live",Name}),
- gen_fsm:send_event(self(), {publish, live, Name}),
- State.
+ Recorder = media_provider:create(Name, live),
+ State#rtmp_client{video_player = Recorder, video_state = publishing}.
View
@@ -37,7 +37,7 @@
-include("../include/ems.hrl").
-include("../include/flv.hrl").
--export([to_tag/2, encode/1]).
+-export([to_tag/1, encode/1]).
encode(#video_frame{type = ?FLV_TAG_TYPE_AUDIO,
@@ -81,15 +81,14 @@ encode(_Frame) ->
?D({"Request to encode undefined", _Frame}).
-to_tag(#channel{msg = Msg,timestamp = FullTimeStamp, type = Type, stream = StreamId}, PrevTimeStamp) ->
+to_tag(#channel{msg = Msg, type = Type, stream = StreamId, timestamp = CurrentTimeStamp}) ->
BodyLength = size(Msg),
- {TimeStampExt, TimeStamp} = case PrevTimeStamp of
+ {TimeStampExt, TimeStamp} = case CurrentTimeStamp of
<<TimeStampExt1:8,TimeStamp1:32>> ->
{TimeStampExt1, TimeStamp1};
_ ->
- {0, PrevTimeStamp}
+ {0, CurrentTimeStamp}
end,
PrevTagSize = size(Msg) + 11,
- {<<Type:8,BodyLength:24,TimeStamp:24,TimeStampExt:8,StreamId:24,Msg/binary,PrevTagSize:32>>,
- FullTimeStamp + PrevTimeStamp}.
+ <<Type:8,BodyLength:24,TimeStamp:24,TimeStampExt:8,StreamId:24,Msg/binary,PrevTagSize:32>>.
View
@@ -41,8 +41,6 @@
-export([init/1, read_frame/2, metadata/1, codec_config/2]).
-behaviour(gen_format).
-% -export([read_header/1,read_frame/1,read_frame/2,to_tag/2,header/1, parse_meta/1, encodeTag/2]).
-
codec_config(video, MediaInfo) ->
Config = decoder_config(video, MediaInfo),
% ?D({"Video config", Config}),
View
@@ -118,21 +118,16 @@ handle_call({set_owner, _Owner}, _From, #media_info{owner = Owner} = MediaInfo)
{reply, {error, {owner_exists, Owner}}, MediaInfo};
-handle_call({publish, Channel}, _From, #media_info{ts_prev = PrevTs, device = Device, clients = Clients} = Recorder) ->
- % ?D({"Record",Channel#channel.id, Channel#channel.type,size(Channel#channel.msg),Channel#channel.timestamp,PrevTs}),
- {Tag,NextTimeStamp} = ems_flv:to_tag(Channel,PrevTs),
+handle_call({publish, Channel}, _From, #media_info{device = Device, clients = Clients} = Recorder) ->
+ Tag = ems_flv:to_tag(Channel),
+ ?D({"Record",Channel#channel.id, Channel#channel.type,Channel#channel.timestamp}),
case Device of
undefined -> ok;
_ -> file:write(Device, Tag)
end,
-
- NextTimeStamp = PrevTs + Channel#channel.timestamp,
- % ?D({"Broadcast",Channel#channel.id,Channel#channel.type,size(Channel#channel.msg),NextTimeStamp}),
- Packet = Channel#channel{id = ems_play:channel_id(Channel#channel.type,1), timestamp = NextTimeStamp},
- % ?D({"Broadcast to", ets:info(Clients, size)}),
+ Packet = Channel#channel{id = ems_play:channel_id(Channel#channel.type,1)},
ets:foldl(fun send_packet/2, Packet, Clients),
-
- {reply, ok, Recorder#media_info{ts_prev = NextTimeStamp}};
+ {reply, ok, Recorder};
handle_call(Request, _From, State) ->
?D({"Undefined call", Request, _From}),
@@ -213,6 +208,15 @@ handle_info({audio_config, Audio}, #media_info{clients = Clients} = MediaInfo) -
handle_info(start, State) ->
{noreply, State};
+handle_info(stop, State) ->
+ {noreply, State};
+
+handle_info(pause, State) ->
+ {noreply, State};
+
+handle_info(resume, State) ->
+ {noreply, State};
+
handle_info(_Info, State) ->
?D({"Undefined info", _Info}),
{noreply, State}.
View
@@ -66,7 +66,7 @@ encode(#channel{id = Id, timestamp = TimeStamp, type= Type, stream = StreamId, c
BinId = encode_id(?RTMP_HDR_NEW,Id),
% NextPacket = <<BinId/binary,TimeStamp:24/big-integer,(size(Data)):24/big-integer,Type:8,StreamId:32/little,Chunk/binary>>,
% encode(Channel, Rest, NextPacket);
- [<<BinId/binary,TimeStamp:24/big-integer,(size(Data)):24/big-integer,Type:8,StreamId:32/little>> | ChunkList].
+ [<<BinId/binary,TimeStamp:24,(size(Data)):24,Type:8,StreamId:32/little>> | ChunkList].
% encode(#channel{id = Id, chunk_size = ChunkSize} = Channel, Data, Packet) ->
% {Chunk,Rest} = chunk(Data, ChunkSize, Id),
@@ -116,17 +116,18 @@ decode_channel_header(Rest, ?RTMP_HDR_CONTINUE, Id, State) ->
decode_channel_header(<<16#ffffff:24, TimeStamp:24, Rest/binary>>, ?RTMP_HDR_TS_CHG, Id, State) ->
{value, Channel} = lists:keysearch(Id, #channel.id, State#rtmp_client.channels),
decode_channel(Channel#channel{timestamp = TimeStamp+16#ffffff}, Rest, State);
-decode_channel_header(<<TimeStamp:24, Rest/binary>>, ?RTMP_HDR_TS_CHG, Id, State) ->
- {value, Channel} = lists:keysearch(Id, #channel.id, State#rtmp_client.channels),
- decode_channel(Channel#channel{timestamp = TimeStamp}, Rest, State);
+
+decode_channel_header(<<Delta:24, Rest/binary>>, ?RTMP_HDR_TS_CHG, Id, State) ->
+ {value, #channel{timestamp = TimeStamp, type = Type} = Channel} = lists:keysearch(Id, #channel.id, State#rtmp_client.channels),
+ decode_channel(Channel#channel{timestamp = TimeStamp + Delta}, Rest, State);
decode_channel_header(<<16#ffffff:24,Length:24,Type:8,TimeStamp:24,Rest/binary>>, ?RTMP_HDR_SAME_SRC, Id, State) ->
{value, Channel} = lists:keysearch(Id, #channel.id, State#rtmp_client.channels),
decode_channel(Channel#channel{timestamp=TimeStamp+16#ffffff,length=Length,type=Type},Rest,State);
-decode_channel_header(<<TimeStamp:24,Length:24,Type:8,Rest/binary>>, ?RTMP_HDR_SAME_SRC, Id, State) ->
- {value, Channel} = lists:keysearch(Id, #channel.id, State#rtmp_client.channels),
- decode_channel(Channel#channel{timestamp=TimeStamp,length=Length,type=Type},Rest,State);
+decode_channel_header(<<Delta:24,Length:24,Type:8,Rest/binary>>, ?RTMP_HDR_SAME_SRC, Id, State) ->
+ {value, #channel{timestamp = TimeStamp} = Channel} = lists:keysearch(Id, #channel.id, State#rtmp_client.channels),
+ decode_channel(Channel#channel{timestamp=TimeStamp + Delta,length=Length,type=Type},Rest,State);
decode_channel_header(<<16#ffffff:24,Length:24,Type:8,StreamId:32/little,TimeStamp:24,Rest/binary>>,?RTMP_HDR_NEW,Id, State) ->
case lists:keysearch(Id, #channel.id, State#rtmp_client.channels) of
@@ -159,7 +160,6 @@ decode_channel(Channel, Data, State) ->
% ?D({"Channels:",lists:map(fun(#channel{id = Id}) -> Id end, State#rtmp_client.channels)}),
push_channel_packet(Channel, Data, State, BytesRequired).
-
% Nothing to do when buffer is small
push_channel_packet(#channel{} = _Channel, Data, State, BytesRequired) when size(Data) < BytesRequired ->

0 comments on commit 76bc923

Please sign in to comment.