Commit e32350e0 authored by daFischer's avatar daFischer

Made loading a lot faster and added loading bars

parent d915c14c
......@@ -17,6 +17,7 @@ Controls::Controls(Video* video, AudioInterface* audio) {
duration=audio->getDuration();
ProtocolPreferences prefs;
progress=0;
//TODO: might make these relative to video's height
timeLineHeight=16;
......@@ -192,6 +193,11 @@ void Controls::draw(SDL_Surface *screen, bool hasDrawn){
//timeLine background
redefineRect(&rect, 0, y, width, timeLineHeight);
SDL_FillRect(screen, &rect, emColor(0x333333));
if(progress>=0)
{
redefineRect(&rect, progress/1000*width/duration, y, width-progress/1000*width/duration, timeLineHeight);
SDL_FillRect(screen, &rect, emColor(0x000000));
}
int currentPosition=audio->getPosition();
//timeLine foreground
......@@ -228,11 +234,11 @@ void Controls::draw(SDL_Surface *screen, bool hasDrawn){
SDL_BlitSurface(times,NULL,screen,&rect);
SDL_FreeSurface(times);
TTF_SetFontOutline(Player::font,0);*/
times=TTF_RenderText_Solid(Player::font,oss2.str().c_str(),black);
times=TTF_RenderText_Solid(Player::font,oss2.str().c_str(),white);
#ifdef EMSCRIPTEN
drawScaledText(screen,times,max(0,min(width-times->w*2,mouseX-times->w - 2)),y-22,2);
drawScaledText(screen,times,max(0,min(width-times->w*2,mouseX-times->w - 2)),y,2);
#else
redefineRect(&rect,max(0,min(width-times->w,mouseX-times->w/2 - 2)),y-24,times->w+4,times->h+4);
redefineRect(&rect,max(0,min(width-times->w,mouseX-times->w/2 - 2)),y-3,times->w+4,times->h+4);
SDL_BlitSurface(times,NULL,screen,&rect);
#endif
SDL_FreeSurface(times);
......
......@@ -37,6 +37,7 @@ public:
void draw(SDL_Surface *screen, bool hasDrawn);
SDL_Rect videoUpdate;
int progress; //timestamp of next to be filled IndexEntry, -1 if all have been filled
private:
......
......@@ -15,40 +15,6 @@ Index::Index(Inflater* in, int numBytes) {
this->numBytes -= 2;
}
bool Index::readIndexEntry(Inflater* in) {
int timestamp;
unsigned char titleLength;
char* title;
int searchableLength;
SizedArray* searchableArray;
SDL_Surface* image;
if(entryNumber>0) {
entryNumber--;
in->readInt(&timestamp);
in->readByte((char*) &titleLength);
title = in->readCharArray(titleLength, true);
title[titleLength] = 0;
in->readInt(&searchableLength);
searchableArray = new SizedArray(searchableLength);
in->readSizedArray(searchableArray);
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) {
if (VERBOSE)
printf("\ncompute index table:\n");
......@@ -169,12 +135,57 @@ SDL_Surface* Index::readThumbnail(Inflater* in, int* numBytes) {
}
}
bool Index::readIndexEntry(Inflater* in) {
int timestamp;
unsigned char titleLength;
char* title;
int searchableLength;
SizedArray* searchableArray;
SDL_Surface* image;
if(entryNumber>0) {
entryNumber--;
in->readInt(&timestamp);
in->readByte((char*) &titleLength);
title = in->readCharArray(titleLength, true);
title[titleLength] = 0;
in->readInt(&searchableLength);
searchableArray = new SizedArray(searchableLength);
in->readSizedArray(searchableArray);
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;
}
/* Video calls this when a not yet filled IndexEntry needs to be filled immediately
*/
void Index::loadUntil(IndexEntry* entry, SDL_Surface* screen, Message** messages, int numMessages, ProtocolPreferences* prefs) {
if(VERBOSE)
printf("Loading IndexEntries from %d s until %d s\n",(*it)->timestamp/1000,entry->timestamp/1000);
for(; it!=index.end() && (*it)->timestamp<=entry->timestamp;)//it is incremented in fill'Surface
fillSurface(screen,messages,numMessages,prefs);
}
bool Index::fillSurface(SDL_Surface* screen, Message** messages, int numMessages, ProtocolPreferences* prefs) {
if (it == index.end())
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()) {
printf("First Message for IndexEntry\n");
currentMessage = 0;
} else {
it--;
......@@ -192,12 +203,16 @@ bool Index::fillSurface(SDL_Surface* screen, Message** messages, int numMessages
(*it)->setWaypoint(waypoint);
it++;
if (it == index.end())
progress=-1;
else
progress=(*it)->timestamp;
return true;
}
IndexEntry* Index::lastBefore(int timestamp) {
for (std::list<IndexEntry*>::reverse_iterator it = index.rbegin(); it != index.rend(); it++)
if ((*it)->timestamp <= timestamp && (*it)->hasImages)
if ((*it)->timestamp <= timestamp)
{
return (IndexEntry*) * it;
}
......
......@@ -28,6 +28,9 @@ public:
IndexEntry* lastBefore(int timestamp);
bool fillSurface(SDL_Surface* screen, Message** messages, int numMessages, ProtocolPreferences* prefs);
bool readIndexEntry(Inflater* in);
void loadUntil(IndexEntry* entry, SDL_Surface* screen, Message** messages, int numMessages, ProtocolPreferences* prefs);
int progress; //timestamp of next to be filled IndexEntry, -1 if all have been filled
private:
//void fillSurfaces(SDL_Surface* screen, Message** messages, int numMessages, ProtocolPreferences* prefs);
......
......@@ -14,15 +14,21 @@ IndexEntry::IndexEntry(char* title, int timestamp, SizedArray* searchable, SDL_S
this->title=title;
this->timestamp=timestamp;
this->searchable=searchable;
this->image=image;
this->thumbnail=image;
waypoint=NULL;
hasThumbnail=image!=NULL;
hasImages=false;
}
void IndexEntry::setWaypoint(SDL_Surface* waypoint) {
this->waypoint=waypoint;
if(image==NULL)
image=scaleDownSurface(waypoint, 5);
if(thumbnail==NULL)
{
SDL_LockSurface(waypoint);
thumbnail=scaleDownSurface(waypoint, 5);
SDL_UnlockSurface(waypoint);
hasThumbnail=true;
}
hasImages=true;
}
......@@ -32,7 +38,7 @@ void IndexEntry::paintWaypoint(SDL_Surface* screen) {
}
IndexEntry::~IndexEntry() {
SDL_FreeSurface(image);
SDL_FreeSurface(thumbnail);
SDL_FreeSurface(waypoint);
if(title!=NULL)
free(title);
......@@ -40,20 +46,20 @@ IndexEntry::~IndexEntry() {
}
SDL_Rect IndexEntry::getRect(SDL_Surface* screen, int x, int y) {
if(image==NULL)
if(!hasThumbnail)
{
SDL_Rect r= {0,0,0,0};
return r;
}
SDL_Rect r= {max(0,min(screen->w-image->w,x-image->w/2)),y-image->h,image->w,image->h};
SDL_Rect r= {max(0,min(screen->w-thumbnail->w,x-thumbnail->w/2)),y-thumbnail->h,thumbnail->w,thumbnail->h};
return r;
}
void IndexEntry::paintThumbnail(SDL_Surface* screen, int x, int y) {
if(image==NULL)
if(!hasThumbnail)
return;
SDL_Rect rect = getRect(screen,x,y);
SDL_BlitSurface(image,NULL,screen,&rect);
SDL_BlitSurface(thumbnail,NULL,screen,&rect);
SDL_UpdateRect(screen, rect.x,rect.y,rect.w,rect.h);
}
......
......@@ -27,13 +27,14 @@ public:
int timestamp;
bool hasImages;
bool hasThumbnail;
private:
SDL_Surface* scaleDownSurface(SDL_Surface* source, char factor);
char* title;
SizedArray* searchable;
SDL_Surface* image;
SDL_Surface* thumbnail;
SDL_Surface* waypoint;
};
......
......@@ -124,35 +124,43 @@ bool Video::loadAsync() {
if(index==NULL)
index=new Index(messages,numMessages);
lastThumbnail.w=0;
loadPhase=8;
case 8:
loadPhase=9;
/*case 8: //Inefficient, instead using gradual or "Just In Time" (when needed) filling of Surfaces
for(int i=0;i<3;i++)
if(!index->fillSurface(screen,messages,numMessages,&prefs))
{
loadPhase=9;
break;
}
break;
break;*/
case 9:
lastTime=1;
failed=false;
break;
}
return failed;
}
void Video::update(int zeit, Controls* controls)
void Video::update(int time, Controls* controls)
{
bool blitRaw=false;
bool blitAnn=false;
//check whether audio has restarted
if(zeit<=2 && (currentMessage>0 && messages[currentMessage-1]->timestamp>zeit*1000+5000))
if(time<=2 && (currentMessage>0 && messages[currentMessage-1]->timestamp>time*1000+5000))
currentMessage=0;
if(time-lastTime>=1) //only fill IndexEntries every second to avoid slowness
{
lastTime=time;
index->fillSurface(screen,messages,numMessages,&prefs);
controls->progress=index->progress;
}
while(currentMessage<numMessages)
{
if(messages[currentMessage]->timestamp > zeit*1000)
if(messages[currentMessage]->timestamp > time*1000)
break;
if(zeit>445 && zeit<460)
if(time>445 && time<460)
printf("message: %d\n",messages[currentMessage]->encoding);
switch(messages[currentMessage]->type){
case ANNOTATION:
......@@ -270,8 +278,18 @@ void Video::seekPosition(int position, Controls* controls){
else
min=(min+max)/2+1;
min--;
IndexEntry* indexEntry=index->lastBefore(messages[min]->timestamp);
if(VERBOSE)
printf("Seeking position at %d seconds. Last message was at %d seconds.\n",position,messages[min]->timestamp/1000);
IndexEntry* indexEntry=index->lastBefore(position*1000);
int lastEntry=indexEntry->timestamp;
if(VERBOSE)
printf("Last IndexEntry was at %d seconds\n",lastEntry/1000);
if(!indexEntry->hasImages)
{
index->loadUntil(indexEntry,screen,messages,numMessages,&prefs);
controls->progress=index->progress;
}
WhiteboardMessage::number=std::min(WhiteboardMessage::number,0);
int firstAnnotation=0;
......@@ -280,7 +298,7 @@ void Video::seekPosition(int position, Controls* controls){
for(int i= min;i>=0;i--)
{
//printf("%s\n",messages[i]->type);
if( (firstRaw!=0 || (lastEntry >= messages[i]->timestamp && indexEntry->hasImages)) &&
if( (firstRaw!=0 || (lastEntry >= messages[i]->timestamp)) &&
(firstAnnotation!=0 || !containsAnnotations) &&
(foundCursor || !containsCursorMessages))
{
......@@ -301,7 +319,7 @@ void Video::seekPosition(int position, Controls* controls){
firstAnnotation=i;
break;
case RAW:
if((lastEntry < messages[i]->timestamp || !indexEntry->hasImages) && (firstRaw==0 && messages[i]->completeScreen(prefs.framebufferWidth, prefs.framebufferHeight)))
if(firstRaw==0 && ((lastEntry >= messages[i]->timestamp) || messages[i]->completeScreen(prefs.framebufferWidth, prefs.framebufferHeight)))
firstRaw=i;
break;
case CURSOR:
......@@ -311,9 +329,11 @@ void Video::seekPosition(int position, Controls* controls){
break;
}
}
if(VERBOSE)
printf("Redrawing raw messages beginning at %d s,\nAnnotations at %d s\n\n",messages[firstRaw]->timestamp/1000,messages[firstAnnotation]->timestamp/1000);
//printf("IndexEntry at %d has%s Images\n",lastEntry, indexEntry->hasImages ? "" : " no");
if(lastEntry>=messages[firstRaw]->timestamp && indexEntry->hasImages)
if(lastEntry>=messages[firstRaw]->timestamp)
{
indexEntry->paintWaypoint(rawScreen);
}
......
......@@ -56,9 +56,11 @@ private:
Message** messages;
int numMessages;
int currentMessage;
Index* index;
SDL_Rect lastThumbnail;
bool original;
int lastTime;
ProtocolPreferences prefs;
Inflater* inflater;
......
......@@ -9,12 +9,11 @@
font-family: arial;
}
html, body {
/* get rid of default spacing on the edges */
margin: 0;
padding: 0;
border: 0;
height: 100%;
/* Don't show a scrool-bar */
/* Don't show a scroll-bar */
overflow: hidden;
}
......@@ -138,7 +137,7 @@
<script type='text/javascript'>
var x_path="TTT";
var x_filename="Diskrete_Strukturen_2013_11_21"; //"<?php $path=$_GET['path']; echo $path; ?>"
var x_filename="Diskrete_Strukturen_2013_11_26"; //"<?php $path=$_GET['path']; echo $path; ?>"
</script>
<div class="emscripten_border" id="canvas_div">
......
This diff is collapsed.
......@@ -34,7 +34,7 @@ const string path = "TTT";
string filename = "";
#else
const string path = "/home/user/NetBeansProjects/TTTPlayer/emBuild/TTT";
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
string filename = "Diskrete_Strukturen_2013_11_26";// 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,14 +7,9 @@
<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/Message.cpp</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Messages/Message.h</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/Index.cpp</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Messages/HextileMessage.cpp</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Video.h</file>
</group>
</open-files>
......
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