Permalink
Browse files

Added pagination system using two attributes currentPage and pageSize

  • Loading branch information...
dayvson committed Mar 28, 2012
1 parent 36285d2 commit b360fc77e9f9639de768154b637ff65083f99638
Showing with 37 additions and 15 deletions.
  1. +17 −6 src/module_main.c
  2. +20 −9 src/storyboard.c
View
@@ -33,8 +33,7 @@
#include "thumbnail.h"
#define BOOL int
-#define DEFAULT_SPLIT "36"
-#define DEFAULT_COLUMNS "1"
+#define ONE_VALUE "1"
#define CONFIG_DEFAULT_ENABLED FALSE
#define CONFIG_DEFAULT_MEDIAS_PATH "/tmp"
#define CONFIG_DEFAULT_JPEG_QUALITY 70
@@ -64,15 +63,16 @@ static int videothumb_handler(request_rec *r) {
LOG_ERROR("request made: %s", r->args);
RequestInfo requestInfo;
+ ImageBuffer jpeg;
void* ctx;
parseQueryString(&ctx, r->args);
strncpy(fullVideoPath, conf->medias_path, MAX_PATH_LENGTH);
strncat(fullVideoPath, getParameter(ctx, "video"), MAX_PATH_LENGTH);
const char* temp = getParameter(ctx, "split");
- requestInfo.split = atoi(temp ? temp : DEFAULT_SPLIT);
+ requestInfo.split = atoi(temp ? temp : ONE_VALUE);
temp = getParameter(ctx, "columns");
- requestInfo.columns = atoi(temp ? temp : DEFAULT_COLUMNS);
+ requestInfo.columns = atoi(temp ? temp : ONE_VALUE);
requestInfo.file = fullVideoPath;
requestInfo.jpegQuality = conf->quality;
@@ -83,11 +83,22 @@ static int videothumb_handler(request_rec *r) {
temp = getParameter(ctx,"height");
if(temp == NULL) requestInfo.height = 0;
else requestInfo.height = atoi(temp);
+
+ temp = getParameter(ctx,"pageSize");
+ requestInfo.pageSize = temp ? atoi(temp) : requestInfo.split;
+
+ temp = getParameter(ctx,"currentPage");
+ requestInfo.currentPage = atoi(temp ? temp : ONE_VALUE);
+
init_libraries();
- ImageBuffer jpeg = get_storyboard(requestInfo);
+ temp = getParameter(ctx, "second");
+ if(temp == NULL) jpeg = get_storyboard(requestInfo);
+ else {
+ requestInfo.second = atoi(temp ? temp : ONE_VALUE);
+ jpeg = get_thumbnail(requestInfo);
+ }
if (jpeg.buffer) {
- LOG_ERROR(">> Retornando JPEG");
ap_set_content_type(r, "image/jpeg");
ap_rwrite(jpeg.buffer, jpeg.size, r);
} else {
View
@@ -29,6 +29,7 @@
*/
#include "storyboard.h"
#include "jpegencoder.h"
+#include <math.h>
ImageBuffer join_images(AVFrame** frames, int count, int columns, int width, int height)
{
@@ -134,23 +135,32 @@ ImageBuffer get_storyboard(RequestInfo info)
LOG_ERROR("unable to open codec");
return memJpeg;
}
+ int counter = 0;
+ int pageSize = info.pageSize;
+ int totalP = ceil((double)info.split/(double)pageSize);
+ int start = (info.currentPage-1) * pageSize;
+ int end = info.currentPage * pageSize;
+ if(info.currentPage == totalP)
+ {
+ end = info.split;
+ pageSize = end-start;
+ }
int64_t *framePosition = (int64_t*)malloc(sizeof(int64_t)*info.split);
split_integer(format_ctx->duration, info.split, framePosition);
ImageSize finalSize = get_new_frame_size(codec_ctx->width, codec_ctx->height, info.width, info.height);
- AVFrame *frameList[info.split];
-
- int counter;
- for (counter = 0; counter<info.split; ++counter)
+ AVFrame *frameList[pageSize];
+ for (start; start<end; ++start)
{
- AVFrame* currentFrame = get_frame_by_second(codec_ctx, format_ctx, video_stream, framePosition[counter]);
+ AVFrame* currentFrame = get_frame_by_second(codec_ctx, format_ctx, video_stream, framePosition[start]);
frameList[counter] = resize_frame(codec_ctx, currentFrame, &finalSize);
av_free(currentFrame);
+ ++counter;
}
- LOG_ERROR("STORYBOARD");
- ImageBuffer rawImage = join_images(frameList, info.split, info.columns, finalSize.width, finalSize.height);
- if (!rawImage.buffer) {
+ ImageBuffer rawImage = join_images(frameList, pageSize, info.columns, finalSize.width, finalSize.height);
+ if (!rawImage.buffer)
+ {
LOG_ERROR("Invalid RAW joined image. Buffer size: %d\n", rawImage.size);
return memJpeg;
}
@@ -163,7 +173,8 @@ ImageBuffer get_storyboard(RequestInfo info)
memJpeg = compress_jpeg(cf, rawImage.buffer, rawImage.width, rawImage.height);
- for (counter=0; counter<info.split; ++counter) {
+ for (counter=0; counter<pageSize; ++counter)
+ {
if (frameList[counter]) av_free(frameList[counter]);
}
av_free(format_ctx);

0 comments on commit b360fc7

Please sign in to comment.