foobar2000 SDK  2015-08-03
Public Member Functions | Private Member Functions | Private Attributes
dynamic_bitrate_helper

#include <dynamic_bitrate_helper.h>

Public Member Functions

 dynamic_bitrate_helper ()
 
void on_frame (double p_duration, t_size p_bits)
 
bool on_update (file_info &p_out, double &p_timestamp_delta)
 
void reset ()
 

Private Member Functions

void init ()
 

Private Attributes

bool m_enabled
 
bool m_inited
 
double m_last_duration
 
t_size m_update_bits
 
double m_update_interval
 
double m_update_time
 

Detailed Description

Definition at line 1 of file dynamic_bitrate_helper.h.

Constructor & Destructor Documentation

dynamic_bitrate_helper::dynamic_bitrate_helper ( )

Definition at line 13 of file dynamic_bitrate_helper.cpp.

14 {
15  reset();
16 }

Member Function Documentation

void dynamic_bitrate_helper::init ( )
private

Definition at line 18 of file dynamic_bitrate_helper.cpp.

19 {
20  if (!m_inited)
21  {
22  m_inited = true;
23  unsigned temp = g_query_settings();
24  if (temp > 0) {m_enabled = true; m_update_interval = 1.0 / (double) temp; }
25  else {m_enabled = false; m_update_interval = 0; }
26  m_last_duration = 0;
27  m_update_bits = 0;
28  m_update_time = 0;
29 
30  }
31 }
static unsigned g_query_settings()
void dynamic_bitrate_helper::on_frame ( double  p_duration,
t_size  p_bits 
)

Definition at line 33 of file dynamic_bitrate_helper.cpp.

34 {
35  init();
36  m_last_duration = p_duration;
37  m_update_time += p_duration;
38  m_update_bits += p_bits;
39 }
bool dynamic_bitrate_helper::on_update ( file_info p_out,
double &  p_timestamp_delta 
)

Definition at line 41 of file dynamic_bitrate_helper.cpp.

42 {
43  init();
44 
45  bool ret = false;
46  if (m_enabled)
47  {
49  {
50  int val = (int) ( ((double)m_update_bits / m_update_time + 500.0) / 1000.0 );
51  if (val != p_out.info_get_bitrate_vbr())
52  {
53  p_timestamp_delta = - (m_update_time - m_last_duration); //relative to last frame beginning;
54  p_out.info_set_bitrate_vbr(val);
55  ret = true;
56  }
57  m_update_bits = 0;
58  m_update_time = 0;
59  }
60  }
61  else
62  {
63  m_update_bits = 0;
64  m_update_time = 0;
65  }
66 
67  return ret;
68 
69 }
void info_set_bitrate_vbr(t_int64 val)
Definition: file_info.h:204
t_int64 info_get_bitrate_vbr() const
Definition: file_info.h:203
void dynamic_bitrate_helper::reset ( )

Definition at line 71 of file dynamic_bitrate_helper.cpp.

72 {
73  m_inited = false;
74 }

Field Documentation

bool dynamic_bitrate_helper::m_enabled
private

Definition at line 14 of file dynamic_bitrate_helper.h.

bool dynamic_bitrate_helper::m_inited
private

Definition at line 14 of file dynamic_bitrate_helper.h.

double dynamic_bitrate_helper::m_last_duration
private

Definition at line 10 of file dynamic_bitrate_helper.h.

t_size dynamic_bitrate_helper::m_update_bits
private

Definition at line 11 of file dynamic_bitrate_helper.h.

double dynamic_bitrate_helper::m_update_interval
private

Definition at line 13 of file dynamic_bitrate_helper.h.

double dynamic_bitrate_helper::m_update_time
private

Definition at line 12 of file dynamic_bitrate_helper.h.


The documentation for this class was generated from the following files: