Commit d915c14c authored by daFischer's avatar daFischer

Made the loading more fluent

parent efc5633b
......@@ -8,10 +8,6 @@
#ifndef AUDIOINTERFACE_H
#define AUDIOINTERFACE_H
#ifndef _STDIO_H
using namespace std;
#endif
using namespace std;
class AudioInterface {
......
......@@ -9,17 +9,22 @@
#include "Inflater.h"
Index::Index(Inflater* in, int numBytes) {
this->numBytes=numBytes;
in->readShort(&entryNumber);
this->numBytes -= 2;
}
bool Index::readIndexEntry(Inflater* in) {
int timestamp;
unsigned char titleLength;
char* title;
int searchableLength;
SizedArray* searchableArray;
SDL_Surface* image;
short entryNumber;
in->readShort(&entryNumber);
numBytes -= 2;
for (int i = 0; i < entryNumber; i++) {
if(entryNumber>0) {
entryNumber--;
in->readInt(&timestamp);
in->readByte((char*) &titleLength);
title = in->readCharArray(titleLength, true);
......@@ -31,14 +36,17 @@ Index::Index(Inflater* in, int numBytes) {
numBytes -= 9 + titleLength + searchableLength;
image = readThumbnail(in, &numBytes);
index.push_back(new IndexEntry(title, timestamp, searchableArray, image));
return true;
}
if (numBytes > 0) {
printf("Index skipping %d bytes\n", numBytes);
in->skipBytes(numBytes);
}
it = index.begin();
//TODO: what if too many bytes have been read?
return false;
}
Index::Index(Message** messages, int numMessages) {
......@@ -161,9 +169,9 @@ SDL_Surface* Index::readThumbnail(Inflater* in, int* numBytes) {
}
}
void Index::fillSurface(SDL_Surface* screen, Message** messages, int numMessages, ProtocolPreferences* prefs) {
bool Index::fillSurface(SDL_Surface* screen, Message** messages, int numMessages, ProtocolPreferences* prefs) {
if (it == index.end())
return;
return false;
SDL_Surface* waypoint = SDL_CreateRGBSurface(SDL_ANYFORMAT, screen->w, screen->h, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask);
if (it == index.begin()) {
......@@ -184,6 +192,7 @@ void Index::fillSurface(SDL_Surface* screen, Message** messages, int numMessages
(*it)->setWaypoint(waypoint);
it++;
return true;
}
IndexEntry* Index::lastBefore(int timestamp) {
......
......@@ -26,7 +26,8 @@ public:
Index(Message** messages, int numMessages);
virtual ~Index();
IndexEntry* lastBefore(int timestamp);
void fillSurface(SDL_Surface* screen, Message** messages, int numMessages, ProtocolPreferences* prefs);
bool fillSurface(SDL_Surface* screen, Message** messages, int numMessages, ProtocolPreferences* prefs);
bool readIndexEntry(Inflater* in);
private:
//void fillSurfaces(SDL_Surface* screen, Message** messages, int numMessages, ProtocolPreferences* prefs);
......@@ -34,6 +35,9 @@ private:
list<IndexEntry*> index;
std::list<IndexEntry*>::iterator it;
int currentMessage;
short entryNumber;
int numBytes;
};
#endif /* INDEXEXTENSION_H */
......
......@@ -75,13 +75,19 @@ Inflater::~Inflater()
bool Inflater::readByte(char* Byte)
{
if(addedChars.size()>0)
{
*Byte=addedChars[0];
addedChars=addedChars.substr(1);
return ret;
}
if (ret != Z_OK)
{
//printf("Video Inflation failed: %d\n",ret);
*Byte=0;
return Z_ERRNO;
}
if(outOffset >= CHUNK - strm.avail_out) //Array out has to be refilled
while(outOffset >= CHUNK - strm.avail_out) //Array out has to be refilled
{
//printf("Refill Array out, %d\n", ret);
if (ret == Z_STREAM_END)
......@@ -212,6 +218,13 @@ bool Inflater::skipBytes(int number) {
return r;
}
void Inflater::addChar(char c) {
addedChars+=c;
}
long int Inflater::getProgress() {
return ftell(source);
}
bool Inflater::endOfFile(){
return ret!=Z_OK;
......
......@@ -31,6 +31,9 @@ public:
//bool readLong(long* s);
bool skipBytes(int number);
bool endOfFile();
long int getProgress();
void addChar(char c);
private:
FILE* source;
......@@ -40,6 +43,8 @@ private:
int ret;
z_stream strm;
string addedChars;
};
#endif /* INFLATER_H */
......
......@@ -19,7 +19,7 @@ DeleteAnnotation::~DeleteAnnotation() {
void DeleteAnnotation::paint(SDL_Surface *screen, ProtocolPreferences* prefs)
{
//printf("Deleted Annotation at (%d, %d)\n",x,y);
printf("Deleted Annotation at (%d, %d)\n",x,y);
deleteAnnotation(x,y);
mustRedraw=true;
}
......@@ -48,20 +48,27 @@ void setUp(){
containsWhiteboard = false;
}
list<Message*> readMessages(Inflater* in, ProtocolPreferences* prefs){
list<Message*> messages;
bool readMessages(list<Message*>* messages, Inflater* in, ProtocolPreferences* prefs){
int timestamp;
if(messages->size()==0)
{
setUp();
timestamp = 0;
}
else
timestamp=messages->back()->timestamp;
Message* message;
int timestamp = 0;
while(!in->endOfFile()){
if(!in->endOfFile()){
// TODO: show progress
message=readMessage(in, prefs);
if(message==NULL)//empty message
{
continue;
return true;
}
// TODO: maybe adding additional timestamp is better suited
if (messages.size() == 0)
if (messages->size() == 0)
message->timestamp = 0;
// use previous timestamp if unset
......@@ -74,12 +81,9 @@ list<Message*> readMessages(Inflater* in, ProtocolPreferences* prefs){
//Maybe output the change for debugging?
message->timestamp = timestamp;
}
// keep timestamp
timestamp = message->timestamp;
// add message to message array
messages.push_back(message);
messages->push_back(message);
// set flags
switch (message->encoding) {
......@@ -118,9 +122,10 @@ list<Message*> readMessages(Inflater* in, ProtocolPreferences* prefs){
printf("Error: message with encoding %d gets no type?\n",message->encoding);
break;
}
return true;
}
//printf("#Messages: %d\n",messages.size());
return messages;
//printf("#Messages: %d\n",messages->size());
return false;
}
Message* readMessage(Inflater* in, ProtocolPreferences* prefs){
......
......@@ -40,7 +40,7 @@ extern bool containsCursorMessages;
extern bool containsAnnotations;
extern bool containsWhiteboard;
extern list<Message*> readMessages(Inflater* in, ProtocolPreferences* prefs);
extern bool readMessages(list<Message*>* messages, Inflater* in, ProtocolPreferences* prefs);
extern Message* readMessage(Inflater* in, ProtocolPreferences* prefs);
extern void setUp();
......
......@@ -26,7 +26,7 @@ WhiteboardMessage::~WhiteboardMessage() {
void WhiteboardMessage::paint(SDL_Surface *screen, ProtocolPreferences* prefs)
{
printf("paint Whiteboard at %d\n",timestamp);
//printf("paint Whiteboard at %d\n",timestamp);
mustRedraw=true;
annotations.clear();
if(pageNumber>0)
......
......@@ -45,16 +45,52 @@ Player::Player(const char* cpath, const char* cfilename) {
return;
}
video=new Video((path+"/"+filename+"_a/"+filename+".ttt").c_str());
#ifdef EMSCRIPTEN
audio=new AudioJS();
#else
audio=new Audio((path+"/"+filename+"_a/"+filename).c_str());
#endif
if(video->failed||audio->hasFailed())
if(audio->hasFailed())
{
printf("Audio failed.\n");
return;
}
video=new Video((path+"/"+filename+"_a/"+filename+".ttt").c_str());
#ifdef EMSCRIPTEN
emscripten_set_main_loop(loadAsync,0,0);
#else
while(loadAsync()){}
#endif
}
#ifdef EMSCRIPTEN
void Player::loadAsync() {
if(player->video->loadAsync())
return; //continue loading
else //finished loading
{
emscripten_cancel_main_loop();
player->videoCallback();
}
}
#else
bool Player::loadAsync() {
if(player->video->loadAsync())
return true; //continue loading
else //finished loading
{
player->videoCallback();
return false;
}
}
#endif
void Player::videoCallback() {
if(video->failed)
{
printf("Audio failed: %s\nVideo failed: %s\n",audio->hasFailed() ? "true" : "false",video->failed ? "true" : "false");
printf("Video failed.\n");
return;
}
......
......@@ -37,6 +37,12 @@ public:
Player(const char*, const char*);
void loop();
virtual ~Player();
#ifdef EMSCRIPTEN
static void loadAsync();
#else
static bool loadAsync();
#endif
void videoCallback();
static TTF_Font* font;
......
This diff is collapsed.
......@@ -32,8 +32,8 @@ using namespace std;
class Video {
public:
Video(const char* path);
//Video(const Video& orig);
virtual ~Video();
bool loadAsync();
void update(int zeit, Controls* controls);
void redrawScreen(Controls* controls, bool fully);
void toggleFullscreen();
......@@ -44,17 +44,25 @@ public:
bool hasThumbnails;
private:
void readExtension(Inflater* in);
void showProgress();
long int fileSize;
long int progress;
SDL_Surface* screen; //Pointer to the main screen surface
SDL_Surface* rawScreen; //Pointer to screen for messages with type RAW
SDL_Surface* annScreen; //Screen that buffers Annotations
list<Message*> m;
Message** messages;
int numMessages;
int currentMessage;
void readExtensions(Inflater* in);
Index* index;
SDL_Rect lastThumbnail;
bool original;
ProtocolPreferences prefs;
Inflater* inflater;
char loadPhase;
};
bool readServerInit(Inflater* in);
......
......@@ -64,7 +64,27 @@ var x_audioLoaded=function(){
}
var x_setProgress=function(percentage)
{
if(percentage<100)
{
x_progress=document.getElementById('x_progress');
x_progress.value=percentage;
}
else
{
x_remove=document.getElementById('x_progress_div');
x_remove.style.display="none";
x_remove=document.getElementById('progress_div');
x_remove.style.display="none";
x_remove=document.getElementById('spinner');
x_remove.style.display="none";
x_remove=document.getElementById('status');
x_remove.style.display="none";
x_remove=document.getElementById('output');
x_remove.style.display="none";
}
}
var x_getPath=function(end){
return x_path+"/"+x_filename+"_a/"+x_filename+"."+end;
......@@ -73,3 +93,9 @@ var x_setAudioSource=function(){
x_audio.innerHTML='<source src="'+x_getPath("ogg")+'" type="audio/ogg"><source src="'+x_getPath("mp3")+'" type="audio/mp3"><source src="'+x_getPath("wav")+'" type="audio/wav">Your browser does not support the audio element.';
}
x_setAudioSource();
var x_resizeCanvas = function(){
var x_canvas_div=document.getElementById('canvas_div');
}
window.onresize=x_resizeCanvas;
\ No newline at end of file
......@@ -7,16 +7,27 @@
<style>
body {
font-family: arial;
}
html, body {
/* get rid of default spacing on the edges */
margin: 0;
padding: none;
padding: 0;
border: 0;
height: 100%;
/* Don't show a scrool-bar */
overflow: hidden;
}
.emscripten { padding-right: 0; margin-left: auto; margin-right: auto; display: block; }
div.emscripten { text-align: center; }
div.emscripten_border { border: 1px solid black;}
div.emscripten_border {
border: 0px none;
height: 100%;
}
/* the canvas *must not* have any border or padding, or mouse coords will be wrong */
canvas.emscripten {
border: 0px none;
height: 100%;
}
#audioplayer {
border:0px none;
......@@ -118,13 +129,16 @@
</span>
</span> -->
<div class="emscripten">
<progress value="0" max="100" id="progress" hidden=1></progress>
<div class="emscripten" id="progress_div">
<progress value="0" max="100" id="progress"></progress>
</div>
<div id="x_progress_div">
<progress value="0" max="100" id="x_progress" style="width:100%"></progress>
</div>
<script type='text/javascript'>
var x_path="TTT";
var x_filename="Programmiersprachen_2013_10_21"; //"<?php $path=$_GET['path']; echo $path; ?>"
var x_filename="Diskrete_Strukturen_2013_11_21"; //"<?php $path=$_GET['path']; echo $path; ?>"
</script>
<div class="emscripten_border" id="canvas_div">
......
This diff is collapsed.
......@@ -3,20 +3,36 @@
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Emscripten-Generated Code</title>
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
<title>Html5 TTT-Player</title>
<style>
body {
font-family: arial;
}
html, body {
/* get rid of default spacing on the edges */
margin: 0;
padding: none;
padding: 0;
border: 0;
height: 100%;
/* Don't show a scrool-bar */
overflow: hidden;
}
.emscripten { padding-right: 0; margin-left: auto; margin-right: auto; display: block; }
div.emscripten { text-align: center; }
div.emscripten_border { border: 1px solid black; display: inline-block;}
div.emscripten_border {
border: 0px none;
height: 100%;
}
/* the canvas *must not* have any border or padding, or mouse coords will be wrong */
canvas.emscripten {
border: 0px none;
height: 100%;
}
#audioplayer {
border:0px none;
......@@ -108,8 +124,8 @@
</head>
<body>
<div class="spinner" id='spinner'></div>
<div class="emscripten" id="status">Downloading...</div>
<div class="spinner" id='spinner' style="display:none"></div>
<div class="emscripten" id="status" style="display:none">Downloading...</div>
<!-- <span id='controls'>
<span><input type="checkbox" id="resize">Resize canvas</span>
......@@ -118,13 +134,13 @@
</span>
</span> -->
<div class="emscripten">
<div class="emscripten" style="display:none">
<progress value="0" max="100" id="progress" hidden=1></progress>
</div>
<script type='text/javascript'>
var x_filename="<?php $name=$_GET['name']; echo $name; ?>";
var x_path="TTT";
var x_path='<?php if(!isset($_GET["path"])) echo "TTT"; else echo $_GET["path"]; ?>'
</script>
<div class="emscripten_border" id="canvas_div">
......@@ -137,7 +153,7 @@
<textarea id="output" rows="8"></textarea>
<textarea id="output" rows="8" style="display:none"></textarea>
<script type='text/javascript'>
var statusElement = document.getElementById('status');
......
......@@ -6,7 +6,7 @@ int main()
#ifdef EMSCRIPTEN
char* memory = (char*) EM_ASM_INT({
var x_memory = _malloc(x_filename.length+1); //TODO: Ensure x_filename is ASCII
writeStringToMemory(x_filename, x_memory);
writeAsciiToMemory(x_filename, x_memory);
return x_memory;
},0);
filename=memory;
......
......@@ -34,7 +34,7 @@ const string path = "TTT";
string filename = "";
#else
const string path = "/home/user/NetBeansProjects/TTTPlayer/emBuild/TTT";
string filename = "ZUE_Diskrete_Strukturen_2013_10_30";// GAD_2014_04_08-merged , Diskrete_Strukturen_2013_11_26 , Programmiersprachen_2013_10_21 , Programmoptimierung_2013_10_16 , ZUE_Diskrete_Strukturen_2013_10_30
string filename = "Programmiersprachen_2013_10_21";// GAD_2014_04_08-merged , Diskrete_Strukturen_2013_11_26 , Programmiersprachen_2013_10_21 , Programmoptimierung_2013_10_16 , ZUE_Diskrete_Strukturen_2013_10_30
#endif
int main();
......
......@@ -7,22 +7,15 @@
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Messages/RectangleAnnotation.h</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Messages/Message.cpp</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Messages/Message.h</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Controls.cpp</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Messages/RectangleAnnotation.cpp</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Inflater.cpp</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Inflater.h</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Constants.h</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/main.h</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Video.cpp</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Messages/Annotation.cpp</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/IndexEntry.cpp</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Index.cpp</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Video.h</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Messages/Message.cpp</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Messages/HighlightAnnotation.h</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Player.cpp</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Controls.h</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Messages/HighlightAnnotation.cpp</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Messages/Annotation.h</file>
</group>
</open-files>
</project-private>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment