diff options
author | Antonius Hellmann <toni@rockbox.org> | 2009-07-14 16:52:18 +0000 |
---|---|---|
committer | Antonius Hellmann <toni@rockbox.org> | 2009-07-14 16:52:18 +0000 |
commit | c92652ecb1ad024020435b8038d8f83c400fcddd (patch) | |
tree | d28e2584b625e23c56c3e1cee2f1863a5b5137e1 /apps/codecs/mp3_enc.c | |
parent | 5905b0be3e92aed0aec499a8429bc805baee03c6 (diff) | |
download | rockbox-c92652ecb1ad024020435b8038d8f83c400fcddd.tar.gz rockbox-c92652ecb1ad024020435b8038d8f83c400fcddd.zip |
Collect encoder data chunks (usually < 1kB) before writing to disk. The reduced number of ci->write() calls give a nice write speedup to the mp3 encoder.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21865 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/mp3_enc.c')
-rw-r--r-- | apps/codecs/mp3_enc.c | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/apps/codecs/mp3_enc.c b/apps/codecs/mp3_enc.c index 94d4c2a5f3..82a8620027 100644 --- a/apps/codecs/mp3_enc.c +++ b/apps/codecs/mp3_enc.c | |||
@@ -2390,6 +2390,9 @@ static inline bool is_file_data_ok(struct enc_file_event_data *filed) | |||
2390 | return filed->rec_file >= 0 && (long)filed->chunk->flags >= 0; | 2390 | return filed->rec_file >= 0 && (long)filed->chunk->flags >= 0; |
2391 | } /* is_event_ok */ | 2391 | } /* is_event_ok */ |
2392 | 2392 | ||
2393 | static unsigned char mp3_data[16384] __attribute__((aligned(4))); | ||
2394 | static unsigned int mp3_data_len; /* current data size in buffer */ | ||
2395 | |||
2393 | /* called very often - inline */ | 2396 | /* called very often - inline */ |
2394 | static inline bool on_write_chunk(struct enc_file_event_data *data) ICODE_ATTR; | 2397 | static inline bool on_write_chunk(struct enc_file_event_data *data) ICODE_ATTR; |
2395 | static inline bool on_write_chunk(struct enc_file_event_data *data) | 2398 | static inline bool on_write_chunk(struct enc_file_event_data *data) |
@@ -2405,9 +2408,20 @@ static inline bool on_write_chunk(struct enc_file_event_data *data) | |||
2405 | return true; | 2408 | return true; |
2406 | } | 2409 | } |
2407 | 2410 | ||
2408 | if (ci->write(data->rec_file, data->chunk->enc_data, | 2411 | /* if current chunk doesn't fit => write collected data */ |
2409 | data->chunk->enc_size) != (ssize_t)data->chunk->enc_size) | 2412 | if (mp3_data_len + data->chunk->enc_size > sizeof(mp3_data)) |
2410 | return false; | 2413 | { |
2414 | if (ci->write(data->rec_file, mp3_data, | ||
2415 | mp3_data_len) != (ssize_t)mp3_data_len) | ||
2416 | return false; | ||
2417 | |||
2418 | mp3_data_len = 0; | ||
2419 | } | ||
2420 | |||
2421 | memcpy(mp3_data+mp3_data_len, data->chunk->enc_data, | ||
2422 | data->chunk->enc_size); | ||
2423 | |||
2424 | mp3_data_len += data->chunk->enc_size; | ||
2411 | 2425 | ||
2412 | data->num_pcm_samples += data->chunk->num_pcm; | 2426 | data->num_pcm_samples += data->chunk->num_pcm; |
2413 | return true; | 2427 | return true; |
@@ -2425,6 +2439,10 @@ static bool on_start_file(struct enc_file_event_data *data) | |||
2425 | 2439 | ||
2426 | /* reset sample count */ | 2440 | /* reset sample count */ |
2427 | data->num_pcm_samples = 0; | 2441 | data->num_pcm_samples = 0; |
2442 | |||
2443 | /* reset buffer write position */ | ||
2444 | mp3_data_len = 0; | ||
2445 | |||
2428 | return true; | 2446 | return true; |
2429 | } /* on_start_file */ | 2447 | } /* on_start_file */ |
2430 | 2448 | ||
@@ -2433,6 +2451,14 @@ static bool on_end_file(struct enc_file_event_data *data) | |||
2433 | if (data->rec_file < 0) | 2451 | if (data->rec_file < 0) |
2434 | return false; /* file already closed, nothing more we can do */ | 2452 | return false; /* file already closed, nothing more we can do */ |
2435 | 2453 | ||
2454 | /* write the remaining mp3_data */ | ||
2455 | if (ci->write(data->rec_file, mp3_data, mp3_data_len) | ||
2456 | != (ssize_t)mp3_data_len) | ||
2457 | return false; | ||
2458 | |||
2459 | /* reset buffer write position */ | ||
2460 | mp3_data_len = 0; | ||
2461 | |||
2436 | /* always _try_ to write the file header, even on error */ | 2462 | /* always _try_ to write the file header, even on error */ |
2437 | if (ci->close(data->rec_file) != 0) | 2463 | if (ci->close(data->rec_file) != 0) |
2438 | return false; | 2464 | return false; |