H.264/MP2T over HTTP ExoPlayer - h.264

I am using this code for playing a simple MPEG-TS using HLS on ExoPlayer:
LoadControl loadControl = new DefaultLoadControl(new BufferPool(BUFFER_SEGMENT_SIZE));
String userAgent = getUserAgent(mContext);
Log.d(TAG, userAgent);
HlsMasterPlaylist manifest = newSimpleMasterPlaylist("http://192.168.1.1/rtp/239.0.0.77:8208");
DataSource dataSource = new HttpDataSource(userAgent, null, null);
HlsChunkSource chunkSource = new HlsChunkSource(dataSource, manifest);
HlsSampleSource sampleSource = new HlsSampleSource(chunkSource, loadControl,
VIDEO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, true, 2);
MediaCodecVideoTrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer(sampleSource,
MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT, 100, mainHandler, null, 50);
MediaCodecAudioTrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource);
ExoPlayer exoPlayer = ExoPlayer.Factory.newInstance(RENDERER_COUNT);
exoPlayer.prepare(videoRenderer,audioRenderer);
// Pass the surface to the video renderer.
exoPlayer.sendMessage(videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surface);
exoPlayer.setPlayWhenReady(true);
With this other method:
private HlsMasterPlaylist newSimpleMasterPlaylist(String mediaPlaylistUrl) {
return new HlsMasterPlaylist(Uri.parse(""),
Collections.singletonList(new Variant(mediaPlaylistUrl, 0)));
}
And it does not work. I get:
11-03 09:56:10.785: D/dalvikvm(10907): GC_FOR_ALLOC freed 3K, 8% free 4422K/4780K, paused 33ms, total 34ms
11-03 09:56:14.005: D/dalvikvm(10907): GC_FOR_ALLOC freed 5K, 7% free 5383K/5732K, paused 40ms, total 40ms
11-03 09:56:18.085: D/dalvikvm(10907): GC_FOR_ALLOC freed 11K, 6% free 6663K/7024K, paused 37ms, total 37ms
11-03 09:56:25.075: D/dalvikvm(10907): GC_FOR_ALLOC freed 14K, 4% free 8392K/8724K, paused 41ms, total 41ms
11-03 09:56:33.115: D/dalvikvm(10907): GC_FOR_ALLOC freed 21K, 4% free 10697K/11036K, paused 37ms, total 37ms
11-03 09:56:44.155: D/dalvikvm(10907): GC_FOR_ALLOC freed 28K, 3% free 13707K/14096K, paused 50ms, total 51ms
11-03 09:56:58.485: D/dalvikvm(10907): GC_FOR_ALLOC freed 40K, 3% free 17741K/18108K, paused 34ms, total 34ms
I think that with a single MPEG2TS file I can create a single media playlist with this code and It would work, but I don't know how to do this.
Thanks

I don't currently see MPEG-TS (or MP2T) support in ExoPlayer.
What makes you believe this approach would work?
Note: What is "HlsChunkSource"? I don't find a reference to it in the standard ExoPlayer source code.

Related

Kiss FFT on TI MSP430FR6989

I am trying to run Kiss FFT (Kiss FFT github) on an MSP430FR6989 Launchpad. For now, I'm just trying to get the kiss_fftr test shown here to work. I am running into an issue with kiss_fftr_alloc(int nfft,int inverse_fft,void * mem, size_t * lenmem). My input is (16, 0, NULL, NULL). The function reaches this point in kiss_fftr.c and then returns NULL due to the !st if statement.
if (lenmem == NULL) {
st = (kiss_fftr_cfg) KISS_FFT_MALLOC (memneeded);
} else {
if (*lenmem >= memneeded)
st = (kiss_fftr_cfg) mem;
*lenmem = memneeded;
}
if (!st)
{
return NULL;
}
Malloc sets st to NULL, so it failed to allocate the memory. I am sure that there is enough memory available in my MCU. My memory allocation in CCS is 35% RAM (736/2048), 3% FRAM1 (1896/48000) and 28% FRAM2 (23144/81912).
Does anyone have advice on how to fix this, or what I should learn to fix this? I don't want to chase down the wrong rabbit hole if memory allocation is not the issue.
What I've tried: When I try running the test code given in the stack overflow link and sending the output array over UART, I get no output. I checked to see if kiss_fft_alloc is working correctly by making an if statement (st == NULL) that would throw a KISS_FFT_ERROR. The error threw at the point mentioned above, but I cannot figure out how to "fix" malloc failing to allocate memory.

web audio api plays beep, beep,... beep at different rate

I am trying to play "beep" sound at different rate based on some sensor readings inside a browser window.
The idea is to "beep, beep, beep, ... beep" faster when the sensor reading is high, and "beep,...beep" slower when the sensor reading is low, all in real-time.
The sensor reading is fed into the browser via socket.io. I can already control a progress bar moving up and down. The audio feedback is an extra feature.
After some googling, I am thinking about using web audio api, creating a sin-wave oscillator, and to turn it on/off with a gain node connect/disconnect.
My question is how do I control the timing in the right way, say I am trying to beep at a range of frequencies from 1 Hz to 20 Hz, and be able to change the frequency dynamically.
I would most specifically NOT turn an oscillator on and off by connecting and disconnecting it - you'd have to do that from the main thread, so not super-predictable.
You can actually do this with a modulating low-frequency oscillator: check out this code:
var context = new AudioContext();
//defaults to A440Hz, sine wave
var src = context.createOscillator();
// Now let's create a modulator to turn beeps on and off
var mod = context.createOscillator();
mod.type="square";
mod.frequency.value = "2"; // Start at 2Hz
var gain = context.createGain();
var scaler = context.createGain();
src.connect(gain);
gain.connect(context.destination);
mod.connect(scaler); // Mod signal is [-1,1]
scaler.gain.value = 0.5; // we need it to be [-0.5,0.5]
gain.gain.value = 0.5; // then it's summed with 0.5, so [0,1]
scaler.connect(gain.gain);
//start it up
src.start(0);
mod.start(0);
// to change rate, change mod.frequency.value to desired frequency

Nape Resulting Impulses

I'm trying to make the player body, when certain condition is met, to go up few "meters" then stop slowly in the "air" and come down.
The gravity is 600
public var gravity:Number = 600;
public var space:Space = new Space(new Vec2(0, gravity));
I thought that for it to go up, the impulse.y should be at least -601, to contradict the force that pushes it down. Although, setting -600 (or even smaller) will shoot it upwards never to be seen again. (even -100).
Yes the impulse is in the update function which means it will constantly add the impulse making it faster per tick. However, when setting -20 it doesn't go up in the y, (it should eventually as impulse is being given to the body per tick).
switch (combo)
{
case "W":
break;
case "WW":
impulse.x = 0.0;
impulse.y = -powerJump;
mainChar.applyImpulse(impulse);
powerJump -= 5;
break;
}
This is not finished and it is not what is described above but it's the gist of it. When condition is met the player should go upwards and the impulse should lose it's force. The problem is I don't know how much is sufficient to counter the gravity impulse. I can do it by trial'n error but I'd rather know how it works, how much impulse is equivalent to gravity=600?

AS3 - How much time until next frame / screen draw

I have a generative art app, and I'd like it to draw as many cycles as possible each frame without reducing the framerate. Is there a way to tell how much time is left until the screen updates/refreshes?
I figure if I can approximate how many milliseconds each cycle takes, then I can run cycles until the amount of time left is less than the average or the peak cycle time, then let the screen refresh, then run another set of cycles.
If you want your app to run at N frames per second, then you can draw in a loop for 1/N seconds*, where N is typically the stage framerate (which you can get and set):
import flash.utils.getTimer;
import flash.events.Event;
private var _time_per_frame:uint;
... Somewhere in your main constructor:
stage.frameRate = 30;
_time_per_frame = 1000 / stage.frameRate;
addEventListener(Event.ENTER_FRAME, handle_enter_frame);
...
private function handle_enter_frame(e:Event):void
{
var t0:uint = getTimer();
while (getTimer()-t0 < _time_per_frame) {
// ... draw some stuff
}
}
Note that this is somewhat of a simplification, and may cause a slower resultant framerate than specified by stage.frameRate, because Flash needs some time to perform the rendering in between frames. But if you're blitting (drawing to a Bitmap on screen) as opposed to drawing in vector or adding Shapes to the screen, then I think the above should actually be pretty accurate.
If the code results in slower-than-desired framerates, you could try something as simple as only taking half the allotted time for a frame, leaving the other half for Flash to render:
_time_per_frame = 500 / stage.frameRate;
There are also FPS monitors around that you could use to monitor your framerate while drawing. Google as3 framerate monitor.
Put this code to main object and check - it will trace time between each frame start .
addEventListener(Event.ENTER_FRAME , oef);
var step:Number = 0;
var last:Number = Date.getTime();
function oef(e:Event):void{
var time:Number = Date.getTime();
step = time - last;
last = time;
trace(step);
}

How do I make my ActionScript 3 Pool Game more realistic with Box2dFlash?

Here is my pool game engine done in Box2dFlash.
I would like to make this simulation more realistic as I received
mixed opinion from pool experts.
Here is my standard wall setting:
var leftWall = _sim.addBox({x:0.9, y:8.15, width: 0.6, height: 11.5, density: 0, fillAlpha: wallAlpha, lineAlpha: wallAlpha});
And of the ball:
_solidBall_7 = _sim.addCircle({x:ballPosX - (ballRadius * 5) - 0.8, y:ballPosY, radius:ballRadius, density: 0.1, linearDamping: 1, isBullet: true, restitution: 0.7, angularDamping: 5, skin: Solid_Bordo});
What other params I might try to improve the realistic movement of the pool game?
Nice work. Looks good.
To make the game mote realistic I would ...
Animate the balls (spinning, hitting the pockets)
Add sounds (hit ball, hit walls, hit pocket)
Add shadows (adds a 3d feel)
The balls should be beneath (masked out) by the walls
Look over the physics parameters