Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
BC
public
mediastreamer2
Commits
0481d7d1
Commit
0481d7d1
authored
Mar 09, 2012
by
Simon Morlat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve audio bitrate driver
parent
b4eecfc2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
35 deletions
+42
-35
src/bitratedriver.c
src/bitratedriver.c
+42
-35
No files found.
src/bitratedriver.c
View file @
0481d7d1
...
@@ -66,7 +66,7 @@ static void apply_ptime(MSAudioBitrateDriver *obj){
...
@@ -66,7 +66,7 @@ static void apply_ptime(MSAudioBitrateDriver *obj){
static
int
inc_ptime
(
MSAudioBitrateDriver
*
obj
){
static
int
inc_ptime
(
MSAudioBitrateDriver
*
obj
){
if
(
obj
->
cur_ptime
>=
max_ptime
){
if
(
obj
->
cur_ptime
>=
max_ptime
){
ms_message
(
"AudioBitrate
Controll
er: maximum ptime reached"
);
ms_message
(
"
MS
AudioBitrate
Driv
er: maximum ptime reached"
);
return
-
1
;
return
-
1
;
}
}
obj
->
cur_ptime
+=
obj
->
min_ptime
;
obj
->
cur_ptime
+=
obj
->
min_ptime
;
...
@@ -77,46 +77,53 @@ static int inc_ptime(MSAudioBitrateDriver *obj){
...
@@ -77,46 +77,53 @@ static int inc_ptime(MSAudioBitrateDriver *obj){
static
int
audio_bitrate_driver_execute_action
(
MSBitrateDriver
*
objbase
,
const
MSRateControlAction
*
action
){
static
int
audio_bitrate_driver_execute_action
(
MSBitrateDriver
*
objbase
,
const
MSRateControlAction
*
action
){
MSAudioBitrateDriver
*
obj
=
(
MSAudioBitrateDriver
*
)
objbase
;
MSAudioBitrateDriver
*
obj
=
(
MSAudioBitrateDriver
*
)
objbase
;
ms_message
(
"MSAudioBitrateDriver: executing action of type %s, value=%i"
,
ms_rate_control_action_type_name
(
action
->
type
),
action
->
value
);
ms_message
(
"MSAudioBitrateDriver: executing action of type %s, value=%i"
,
ms_rate_control_action_type_name
(
action
->
type
),
action
->
value
);
if
(
obj
->
nom_bitrate
==
0
){
ms_filter_call_method
(
obj
->
encoder
,
MS_FILTER_GET_BITRATE
,
&
obj
->
nom_bitrate
);
if
(
obj
->
nom_bitrate
==
0
){
ms_warning
(
"MSAVBitrateDriver: Not doing adaptive rate control on audio encoder, it does not seem to support that."
);
obj
->
nom_bitrate
=-
1
;
}
}
if
(
action
->
type
==
MSRateControlActionDecreaseBitrate
){
if
(
action
->
type
==
MSRateControlActionDecreaseBitrate
){
/*reducing bitrate of the codec actually doesn't work very well (not enough). Increasing ptime is much more efficient*/
/*reducing bitrate of the codec isn't sufficient. Increasing ptime is much more efficient*/
if
(
inc_ptime
(
obj
)
==-
1
){
inc_ptime
(
obj
);
if
(
obj
->
nom_bitrate
>
0
){
if
(
obj
->
nom_bitrate
>
0
){
int
cur_br
=
0
;
int
cur_br
=
0
;
int
new_br
;
int
new_br
;
if
(
obj
->
nom_bitrate
==
0
){
if
(
ms_filter_call_method
(
obj
->
encoder
,
MS_FILTER_GET_BITRATE
,
&
obj
->
cur_bitrate
)
!=
0
){
if
(
ms_filter_call_method
(
obj
->
encoder
,
MS_FILTER_GET_BITRATE
,
&
obj
->
nom_bitrate
)
!=
0
){
ms_message
(
"MSAudioBitrateDriver: Encoder has current bitrate %i"
,
obj
->
cur_bitrate
);
ms_message
(
"MSAudioBitrateDriver: Encoder has nominal bitrate %i"
,
obj
->
nom_bitrate
);
}
}
/*if max ptime is reached, then try to reduce the codec bitrate if possible */
obj
->
cur_bitrate
=
obj
->
nom_bitrate
;
}
if
(
ms_filter_call_method
(
obj
->
encoder
,
MS_FILTER_GET_BITRATE
,
&
cur_br
)
!=
0
){
/*if max ptime is reached, then try to reduce the codec bitrate if possible */
ms_message
(
"MSAudioBitrateDriver: GET_BITRATE failed"
);
return
0
;
if
(
ms_filter_call_method
(
obj
->
encoder
,
MS_FILTER_GET_BITRATE
,
&
cur_br
)
!=
0
){
}
ms_message
(
"AudioBitrateController: GET_BITRATE failed"
);
new_br
=
cur_br
-
((
cur_br
*
action
->
value
)
/
100
);
return
0
;
}
ms_message
(
"MSAudioBitrateDriver: Attempting to reduce audio bitrate to %i"
,
new_br
);
new_br
=
cur_br
-
((
cur_br
*
action
->
value
)
/
100
);
if
(
ms_filter_call_method
(
obj
->
encoder
,
MS_FILTER_SET_BITRATE
,
&
new_br
)
!=
0
){
ms_message
(
"MSAudioBitrateDriver: SET_BITRATE failed, incrementing ptime"
);
ms_message
(
"MSAudioBitrateDriver: Attempting to reduce audio bitrate to %i"
,
new_br
);
inc_ptime
(
obj
);
if
(
ms_filter_call_method
(
obj
->
encoder
,
MS_FILTER_SET_BITRATE
,
&
new_br
)
!=
0
){
return
0
;
ms_message
(
"MSAudioBitrateDriver: SET_BITRATE failed, incrementing ptime"
);
inc_ptime
(
obj
);
return
0
;
}
new_br
=
0
;
ms_filter_call_method
(
obj
->
encoder
,
MS_FILTER_GET_BITRATE
,
&
new_br
);
ms_message
(
"MSAudioBitrateDriver: bitrate actually set to %i"
,
new_br
);
obj
->
cur_bitrate
=
new_br
;
}
}
new_br
=
0
;
ms_filter_call_method
(
obj
->
encoder
,
MS_FILTER_GET_BITRATE
,
&
new_br
);
ms_message
(
"MSAudioBitrateDriver: bitrate actually set to %i"
,
new_br
);
obj
->
cur_bitrate
=
new_br
;
}
}
}
else
if
(
action
->
type
==
MSRateControlActionDecreasePacketRate
){
}
else
if
(
action
->
type
==
MSRateControlActionDecreasePacketRate
){
inc_ptime
(
obj
);
inc_ptime
(
obj
);
}
else
if
(
action
->
type
==
MSRateControlActionIncreaseQuality
){
}
else
if
(
action
->
type
==
MSRateControlActionIncreaseQuality
){
if
(
obj
->
cur_bitrate
<
obj
->
nom_bitrate
){
if
(
obj
->
nom_bitrate
>
0
&&
obj
->
cur_bitrate
<
obj
->
nom_bitrate
){
ms_message
(
"MSAudioBitrateDriver: increasing bitrate of codec"
);
obj
->
cur_bitrate
=
(
obj
->
cur_bitrate
*
120
)
/
100
;
if
(
ms_filter_call_method
(
obj
->
encoder
,
MS_FILTER_SET_BITRATE
,
&
obj
->
nom_bitrate
)
!=
0
){
if
(
obj
->
cur_bitrate
>
obj
->
nom_bitrate
)
obj
->
cur_bitrate
=
obj
->
nom_bitrate
;
ms_message
(
"MSAudioBitrateDriver: could not restore nominal codec bitrate (%i)"
,
obj
->
nom_bitrate
);
ms_message
(
"MSAudioBitrateDriver: increasing bitrate of codec to %i"
,
obj
->
cur_bitrate
);
if
(
ms_filter_call_method
(
obj
->
encoder
,
MS_FILTER_SET_BITRATE
,
&
obj
->
cur_bitrate
)
!=
0
){
ms_message
(
"MSAudioBitrateDriver: could not set codec bitrate to %i"
,
obj
->
cur_bitrate
);
}
else
obj
->
cur_bitrate
=
obj
->
nom_bitrate
;
}
else
obj
->
cur_bitrate
=
obj
->
nom_bitrate
;
}
else
if
(
obj
->
cur_ptime
>
obj
->
min_ptime
){
}
else
if
(
obj
->
cur_ptime
>
obj
->
min_ptime
){
obj
->
cur_ptime
-=
obj
->
min_ptime
;
obj
->
cur_ptime
-=
obj
->
min_ptime
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment