StringForRate()
Introduce a function to generate the string representation of a bitrate (kbps, mbps, gbps, etc..) * Factor out the code from MediaPlayer InfoWindow * Allow different bases (/1000 or /1024)
This commit is contained in:
@@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010 Haiku Inc. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef STRING_FOR_RATE_H
|
||||||
|
#define STRING_FOR_RATE_H
|
||||||
|
|
||||||
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace BPrivate {
|
||||||
|
|
||||||
|
|
||||||
|
const char* string_for_rate(double rate, char* string, size_t stringSize,
|
||||||
|
double base = 1024.0f);
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace BPrivate
|
||||||
|
|
||||||
|
|
||||||
|
using BPrivate::string_for_rate;
|
||||||
|
|
||||||
|
|
||||||
|
#endif // COLOR_QUANTIZER_H
|
||||||
@@ -32,6 +32,7 @@
|
|||||||
#include <Mime.h>
|
#include <Mime.h>
|
||||||
#include <NodeInfo.h>
|
#include <NodeInfo.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
#include <StringForRate.h>
|
||||||
#include <StringView.h>
|
#include <StringView.h>
|
||||||
#include <TextView.h>
|
#include <TextView.h>
|
||||||
|
|
||||||
@@ -407,14 +408,10 @@ printf("InfoWin::Update(0x%08lx)\n", which);
|
|||||||
}
|
}
|
||||||
if (format.type == B_MEDIA_ENCODED_AUDIO) {
|
if (format.type == B_MEDIA_ENCODED_AUDIO) {
|
||||||
float br = format.u.encoded_audio.bit_rate;
|
float br = format.u.encoded_audio.bit_rate;
|
||||||
if (br > 0.0) {
|
char string[20] = "";
|
||||||
char rateString[20];
|
if (br > 0.0)
|
||||||
snprintf(rateString, sizeof(rateString), B_TRANSLATE(", %.0f kbps"),
|
s << ", " << string_for_rate(br, string, 20, 1000.0);
|
||||||
br / 1000);
|
|
||||||
s << rateString;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s << "\n\n";
|
s << "\n\n";
|
||||||
fContentsView->Insert(s.String());
|
fContentsView->Insert(s.String());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ StaticLibrary libshared.a :
|
|||||||
RWLockManager.cpp
|
RWLockManager.cpp
|
||||||
SHA256.cpp
|
SHA256.cpp
|
||||||
ShakeTrackingFilter.cpp
|
ShakeTrackingFilter.cpp
|
||||||
|
StringForRate.cpp
|
||||||
StringForSize.cpp
|
StringForSize.cpp
|
||||||
Variant.cpp
|
Variant.cpp
|
||||||
;
|
;
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012 Haiku Inc. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "StringForRate.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <SystemCatalog.h>
|
||||||
|
|
||||||
|
using BPrivate::gSystemCatalog;
|
||||||
|
|
||||||
|
|
||||||
|
#undef B_TRANSLATION_CONTEXT
|
||||||
|
#define B_TRANSLATION_CONTEXT "StringForRate"
|
||||||
|
|
||||||
|
|
||||||
|
namespace BPrivate {
|
||||||
|
|
||||||
|
|
||||||
|
const char*
|
||||||
|
string_for_rate(double rate, char* string, size_t stringSize, double base)
|
||||||
|
{
|
||||||
|
double kbps = rate / base;
|
||||||
|
if (kbps < 1.0) {
|
||||||
|
const char* trKey = B_TRANSLATE_MARK("%.0f bps");
|
||||||
|
snprintf(string, stringSize, gSystemCatalog.GetString(trKey,
|
||||||
|
B_TRANSLATION_CONTEXT), (int)rate);
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
double mbps = kbps / base;
|
||||||
|
if (mbps < 1.0) {
|
||||||
|
const char* trKey = B_TRANSLATE_MARK("%.0f kbps");
|
||||||
|
snprintf(string, stringSize, gSystemCatalog.GetString(trKey,
|
||||||
|
B_TRANSLATION_CONTEXT), kbps);
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
double gbps = mbps / base;
|
||||||
|
if (gbps < 1.0) {
|
||||||
|
const char* trKey = B_TRANSLATE_MARK("%.0f mbps");
|
||||||
|
snprintf(string, stringSize, gSystemCatalog.GetString(trKey,
|
||||||
|
B_TRANSLATION_CONTEXT), mbps);
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
double tbps = gbps / base;
|
||||||
|
if (tbps < 1.0) {
|
||||||
|
const char* trKey = B_TRANSLATE_MARK("%.0f gbps");
|
||||||
|
snprintf(string, stringSize, gSystemCatalog.GetString(trKey,
|
||||||
|
B_TRANSLATION_CONTEXT), gbps);
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
const char* trKey = B_TRANSLATE_MARK("%.0f tbps");
|
||||||
|
snprintf(string, stringSize, gSystemCatalog.GetString(trKey,
|
||||||
|
B_TRANSLATION_CONTEXT), tbps);
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace BPrivate
|
||||||
|
|
||||||
Reference in New Issue
Block a user