Skip to content
This repository has been archived by the owner on Nov 19, 2022. It is now read-only.

Commit

Permalink
Sandbox libvorbis + benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
shravanrn committed Nov 12, 2019
1 parent b73ab44 commit e418692
Show file tree
Hide file tree
Showing 12 changed files with 526 additions and 13 deletions.
280 changes: 274 additions & 6 deletions dom/media/platforms/agnostic/VorbisDecoder.cpp

Large diffs are not rendered by default.

44 changes: 44 additions & 0 deletions dom/media/platforms/agnostic/VorbisDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#if !defined(VorbisDecoder_h_)
#define VorbisDecoder_h_

#include <chrono>
#include <atomic>
using namespace std::chrono;

#include "AudioConverter.h"
#include "PlatformDecoderModule.h"
#include "mozilla/Maybe.h"
Expand All @@ -16,6 +20,31 @@
#include "vorbis/codec.h"
#endif

#if !defined(USE_SANDBOXING_BUFFERS)
#error "No build option defined. File VorbisDecoder.h is being included from an unexpected location"
#endif

#if defined(NACL_SANDBOX_USE_NEW_CPP_API)
#include "RLBox_NaCl.h"
using TRLSandbox = RLBox_NaCl;
#elif defined(WASM_SANDBOX_USE_CPP_API)
#include "RLBox_Wasm.h"
using TRLSandbox = RLBox_Wasm;
#elif defined(PS_SANDBOX_USE_NEW_CPP_API)
#define USE_LIBVORBIS
#include "ProcessSandbox.h"
#include "RLBox_Process.h"
using TRLSandbox = RLBox_Process<VorbisProcessSandbox>;
#undef USE_LIBVORBIS
#endif

#if defined(NACL_SANDBOX_USE_NEW_CPP_API) || defined(WASM_SANDBOX_USE_NEW_CPP_API) || defined(PS_SANDBOX_USE_NEW_CPP_API)
#include "rlbox.h"
using namespace rlbox;
#include "vorbislib_structs_for_cpp_api_new.h"
#endif


namespace mozilla {

class VorbisDataDecoder : public MediaDataDecoder
Expand All @@ -39,17 +68,32 @@ class VorbisDataDecoder : public MediaDataDecoder
static const AudioConfig::Channel* VorbisLayout(uint32_t aChannels);

private:

std::atomic_ullong vorbisDecodeInvocations{0};
std::atomic_ullong timeBetweenVorbisDecode{0};
std::atomic_ullong timeSpentInVorbisDecode{0};
std::atomic_ullong previousVorbisDecodeCall;
std::atomic_ullong bitsProcessedByVorbis{0};

nsresult DecodeHeader(const unsigned char* aData, size_t aLength);
RefPtr<DecodePromise> ProcessDecode(MediaRawData* aSample);

const AudioInfo& mInfo;
const RefPtr<TaskQueue> mTaskQueue;

// Vorbis decoder state
#if defined(NACL_SANDBOX_USE_NEW_CPP_API) || defined(WASM_SANDBOX_USE_NEW_CPP_API) || defined(PS_SANDBOX_USE_NEW_CPP_API)
RLBoxSandbox<TRLSandbox>* rlbox_vorbis;
tainted<vorbis_info*, TRLSandbox> p_mVorbisInfo;
tainted<vorbis_comment*, TRLSandbox> p_mVorbisComment;
tainted<vorbis_dsp_state*, TRLSandbox> p_mVorbisDsp;
tainted<vorbis_block*, TRLSandbox> p_mVorbisBlock;
#else
vorbis_info mVorbisInfo;
vorbis_comment mVorbisComment;
vorbis_dsp_state mVorbisDsp;
vorbis_block mVorbisBlock;
#endif

int64_t mPacketCount;
int64_t mFrames;
Expand Down
2 changes: 2 additions & 0 deletions dom/media/platforms/moz_copy_new_nacl_cpp.build
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,13 @@ FINAL_LIBRARY = 'xul'
DEFINES['STARTUP_LIBRARY_PATH'] = '"Sandboxing_NaCl/native_client/scons-out/nacl_irt-x86-64/staging/irt_core.nexe"'
DEFINES['SANDBOX_INIT_APP_THEORA'] = '"libtheora/builds/x64/nacl_build/mainCombine/libtheora.nexe"'
DEFINES['SANDBOX_INIT_APP_VPX'] = '"libvpx/builds/x64/nacl_build/mainCombine/libvpx.nexe"'
DEFINES['SANDBOX_INIT_APP_VORBIS'] = '"libvorbis/builds/x64/nacl_build/mainCombine/libvorbis.nexe"'

LOCAL_INCLUDES += [
'/../rlbox_api',
'/../Sandboxing_NaCl/native_client/src/trusted/dyn_ldr',
'/media/libtheora_naclport/',
'/media/libvorbis_naclport/',
'/media/libvpx_naclport/',
]

Expand Down
8 changes: 5 additions & 3 deletions dom/media/platforms/moz_copy_new_ps_cpp.build
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,17 @@ FINAL_LIBRARY = 'xul'
DEFINES['STARTUP_LIBRARY_PATH'] = '""'
DEFINES['SANDBOX_INIT_APP_THEORA'] = '"ProcessSandbox/ProcessSandbox_otherside_theora64"'
DEFINES['SANDBOX_INIT_APP_VPX'] = '"ProcessSandbox/ProcessSandbox_otherside_vpx64"'
DEFINES['SANDBOX_INIT_APP_VORBIS'] = '"ProcessSandbox/ProcessSandbox_otherside_vorbis64"'

LOCAL_INCLUDES += [
'/../ProcessSandbox',
'/../rlbox_api',
'/media/libtheora_naclport/'
,'/media/libvpx_naclport/',
'/media/libtheora_naclport/',
'/media/libvorbis_naclport/',
'/media/libvpx_naclport/',
]

if CONFIG['GNU_CXX']:
CXXFLAGS += ['-Wno-error=shadow']

OS_LIBS += ['-L$(topsrcdir)/../ProcessSandbox', '-lProcessSandbox_theora64', '-lProcessSandbox_vpx64']
OS_LIBS += ['-L$(topsrcdir)/../ProcessSandbox', '-lProcessSandbox_theora64', '-lProcessSandbox_vpx64', '-lProcessSandbox_vorbis64']
9 changes: 6 additions & 3 deletions dom/media/platforms/moz_copy_new_ps_cpp_mutex.build
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,18 @@ FINAL_LIBRARY = 'xul'
DEFINES['STARTUP_LIBRARY_PATH'] = '""'
DEFINES['SANDBOX_INIT_APP_THEORA'] = '"ProcessSandbox/ProcessSandbox_otherside_theora64"'
DEFINES['SANDBOX_INIT_APP_VPX'] = '"ProcessSandbox/ProcessSandbox_otherside_vpx64"'
DEFINES['SANDBOX_INIT_APP_VORBIS'] = '"ProcessSandbox/ProcessSandbox_otherside_vorbis64"'

LOCAL_INCLUDES += [
'/../ProcessSandbox',
'/../rlbox_api',
'/media/libtheora_naclport/'
,'/media/libvpx_naclport/',
'/media/libtheora_naclport/',
'/media/libvorbis_naclport/',
'/media/libvpx_naclport/',
]

if CONFIG['GNU_CXX']:
CXXFLAGS += ['-Wno-error=shadow']

OS_LIBS += ['-L$(topsrcdir)/../ProcessSandbox', '-lProcessSandbox_theora64', '-lProcessSandbox_vpx64']

OS_LIBS += ['-L$(topsrcdir)/../ProcessSandbox', '-lProcessSandbox_theora64', '-lProcessSandbox_vpx64','-lProcessSandbox_vorbis64']
14 changes: 14 additions & 0 deletions media/libvorbis_naclport/moz.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

with Files("**"):
BUG_COMPONENT = ("Core", "ImageLib")

EXPORTS += [
'vorbislib_structs_for_cpp_api_new.h',
]

FINAL_LIBRARY = 'gkmedias'
110 changes: 110 additions & 0 deletions media/libvorbis_naclport/vorbislib_structs_for_cpp_api_new.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#define sandbox_fields_reflection_vorbislib_class_vorbis_info(f, g, ...) \
f(int, version, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(int, channels, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(long, rate, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(long, bitrate_upper, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(long, bitrate_nominal, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(long, bitrate_lower, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(long, bitrate_window, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(void*, codec_setup, FIELD_NORMAL, ##__VA_ARGS__)

#define sandbox_fields_reflection_vorbislib_class_vorbis_comment(f, g, ...) \
f(char **, user_comments, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(int *, comment_lengths, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(int , comments, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(char *, vendor, FIELD_NORMAL, ##__VA_ARGS__)

#define sandbox_fields_reflection_vorbislib_class_vorbis_dsp_state(f, g, ...) \
f(int , analysisp, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(vorbis_info *, vi, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(ogg_int32_t **, pcm, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(ogg_int32_t **, pcmret, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(int , pcm_storage, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(int , pcm_current, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(int , pcm_returned, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(int , preextrapolate, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(int , eofflag, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(long , lW, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(long , W, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(long , nW, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(long , centerW, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(ogg_int64_t , granulepos, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(ogg_int64_t , sequence, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(void *, backend_state, FIELD_NORMAL, ##__VA_ARGS__)

#define sandbox_fields_reflection_vorbislib_class_oggpack_buffer(f, g, ...) \
f(long , endbyte, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(int , endbit, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(unsigned char *, buffer, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(unsigned char *, ptr, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(long , storage, FIELD_NORMAL, ##__VA_ARGS__) \
g()

#define sandbox_fields_reflection_vorbislib_class_vorbis_block(f, g, ...) \
f(ogg_int32_t ** , pcm, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(oggpack_buffer , opb, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(long , lW, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(long , W, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(long , nW, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(int , pcmend, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(int , mode, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(int , eofflag, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(ogg_int64_t , granulepos, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(ogg_int64_t , sequence, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(vorbis_dsp_state * , vd, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(void *, localstore, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(long , localtop, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(long , localalloc, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(long , totaluse, FIELD_NORMAL, ##__VA_ARGS__) \
g() \
f(struct alloc_chain *, reap, FIELD_NORMAL, ##__VA_ARGS__)

#define sandbox_fields_reflection_vorbislib_allClasses(f, ...) \
f(vorbis_info, vorbislib, ##__VA_ARGS__) \
f(vorbis_comment, vorbislib, ##__VA_ARGS__) \
f(vorbis_dsp_state, vorbislib, ##__VA_ARGS__) \
f(oggpack_buffer, vorbislib, ##__VA_ARGS__) \
f(vorbis_block, vorbislib, ##__VA_ARGS__)
5 changes: 4 additions & 1 deletion testing/talos/talos.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,11 @@
"vpx_test": {
"tests": ["vpx_perf"]
},
"vorbis_test": {
"tests": ["vorbis_perf"]
},
"rlbox_test": {
"tests": [ "jpeg_perf", "png_perf", "zlib_page_render", "theora_perf", "vpx_perf" ]
"tests": [ "jpeg_perf", "png_perf", "zlib_page_render", "theora_perf", "vpx_perf", "vorbis_perf" ]
},
"rlbox_scaling": {
"tests": ["jpeg_scaling_1", "jpeg_scaling_1_1", "jpeg_scaling_1_2", "jpeg_scaling_1_3", "jpeg_scaling_1_4", "jpeg_scaling_1_5", "jpeg_scaling_1_6", "jpeg_scaling_2", "jpeg_scaling_3", "jpeg_scaling_4", "jpeg_scaling_5", "jpeg_scaling_6", "jpeg_scaling_7"]
Expand Down
16 changes: 16 additions & 0 deletions testing/talos/talos/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,22 @@ class vpx_perf(PageloaderTest):
unit = 'ms'
timeout = 72000

@register_test()
class vorbis_perf(PageloaderTest):
"""
Test the bit rate when playing an ogg file
"""
tpmanifest = '${talos}/tests/vorbis_perf/tests.manifest'
tpcycles = 1
tploadnocache = True
tppagecycles = 5
tpmozafterpaint = True
gecko_profile_interval = 1
gecko_profile_entries = 10000000
# filters = filter.ignore_first.prepare(5) + filter.median.prepare()
filters = filter.mean.prepare()
unit = 'ms'
timeout = 72000

@register_test()
class tscrollx(PageloaderTest):
Expand Down
50 changes: 50 additions & 0 deletions testing/talos/talos/tests/vorbis_perf/audiotest.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Test video page</title>
<script type="text/javascript" src="chrome://talos-powers-content/content/TalosContentProfiler.js"></script>
</head>
<body>
<audio src='example.ogg' alt='Test' controls>
<script type="text/javascript">
var delaySum = 0.0;
var samples = 0;
var v = document.getElementsByTagName("audio")[0];
var shouldMeasure = false;
var start = 0;

function refreshLoop() {
window.requestAnimationFrame(() => {
delaySum += v.mozFrameDelay;
samples += 1;
document.title = "Delay: " + (1000 * delaySum/samples).toFixed(2) + " Max allowed: 16.67";
if (shouldMeasure) {
refreshLoop();
}
});
}

v.addEventListener("play", function() {
shouldMeasure = true;
setTimeout(refreshLoop, 1000 /* 1sec */);
});

v.addEventListener("pause", function() {
shouldMeasure = false;
TalosContentProfiler.pause("audio test finish", true).then(() => {
var result = (1000 * delaySum/samples).toFixed(2);
tpRecordTime(result, start);
parent.reportResults(result, start);
});
});

addEventListener("load", function() {
TalosContentProfiler.resume("audio test start", true).then(() => {
start = new Date();
v.play();
});
});
</script>
</body>
</html>
Binary file not shown.
1 change: 1 addition & 0 deletions testing/talos/talos/tests/vorbis_perf/tests.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
% http://localhost/tests/vorbis_perf/audiotest.html

0 comments on commit e418692

Please sign in to comment.