3 #include "ffmpeg/avcodec.h"
4 #include "ffmpeg/swscale.h"
8 /* The "Check for update" thread */
11 hb_thread_t * update_thread;
13 /* This thread's only purpose is to check other threads'
16 hb_thread_t * main_thread;
19 /* DVD/file scan thread */
20 hb_list_t * list_title;
21 hb_thread_t * scan_thread;
23 /* The thread which processes the jobs. Others threads are launched
24 from this one (see work.c) */
26 hb_job_t * current_job;
28 int job_count_permanent;
29 volatile int work_die;
31 hb_thread_t * work_thread;
35 hb_lock_t * state_lock;
39 hb_lock_t * pause_lock;
40 /* For MacGui active queue
41 increments each time the scan thread completes*/
46 hb_work_object_t * hb_objects = NULL;
48 static void thread_func( void * );
51 * Registers work objects, by adding the work object to a liked list.
52 * @param w Handle to hb_work_object_t to register.
54 void hb_register( hb_work_object_t * w )
61 * libhb initialization routine.
62 * @param verbose HB_DEBUG_NONE or HB_DEBUG_ALL.
63 * @param update_check signals libhb to check for updated version from HandBrake website.
64 * @return Handle to hb_handle_t for use on all subsequent calls to libhb.
66 hb_handle_t * hb_init_real( int verbose, int update_check )
68 hb_handle_t * h = calloc( sizeof( hb_handle_t ), 1 );
71 /* See hb_log() in common.c */
72 if( verbose > HB_DEBUG_NONE )
74 putenv( "HB_DEBUG=1" );
75 av_log_set_level(AV_LOG_DEBUG);
78 /* Check for an update on the website if asked to */
83 hb_log( "hb_init: checking for updates" );
85 h->update_thread = hb_update_init( &h->build, h->version );
89 if( hb_thread_has_exited( h->update_thread ) )
91 /* Immediate success or failure */
92 hb_thread_close( &h->update_thread );
95 if( hb_get_date() > date + 1000 )
97 /* Still nothing after one second. Connection problem,
99 hb_log( "hb_init: connection problem, not waiting for "
107 /* CPU count detection */
108 hb_log( "hb_init: checking cpu count" );
109 h->cpu_count = hb_get_cpu_count();
111 h->list_title = hb_list_init();
112 h->jobs = hb_list_init();
114 h->state_lock = hb_lock_init();
115 h->state.state = HB_STATE_IDLE;
117 h->pause_lock = hb_lock_init();
121 avcodec_register_all();
122 av_register_codec_parser( &mpegaudio_parser);
124 /* Start library thread */
125 hb_log( "hb_init: starting libhb thread" );
127 h->main_thread = hb_thread_init( "libhb", thread_func, h,
128 HB_NORMAL_PRIORITY );
132 /* Set the scan count to start at 0 */
137 * libhb initialization routine.
138 * This version is to use when calling the dylib, the macro hb_init isn't available from a dylib call!
139 * @param verbose HB_DEBUG_NONE or HB_DEBUG_ALL.
140 * @param update_check signals libhb to check for updated version from HandBrake website.
141 * @return Handle to hb_handle_t for use on all subsequent calls to libhb.
143 hb_handle_t * hb_init_dl( int verbose, int update_check )
145 hb_handle_t * h = calloc( sizeof( hb_handle_t ), 1 );
148 /* See hb_log() in common.c */
149 if( verbose > HB_DEBUG_NONE )
151 putenv( "HB_DEBUG=1" );
152 av_log_set_level(AV_LOG_DEBUG);
155 /* Check for an update on the website if asked to */
160 hb_log( "hb_init: checking for updates" );
161 date = hb_get_date();
162 h->update_thread = hb_update_init( &h->build, h->version );
166 if( hb_thread_has_exited( h->update_thread ) )
168 /* Immediate success or failure */
169 hb_thread_close( &h->update_thread );
172 if( hb_get_date() > date + 1000 )
174 /* Still nothing after one second. Connection problem,
175 let the thread die */
176 hb_log( "hb_init: connection problem, not waiting for "
184 /* CPU count detection */
185 hb_log( "hb_init: checking cpu count" );
186 h->cpu_count = hb_get_cpu_count();
188 h->list_title = hb_list_init();
189 h->jobs = hb_list_init();
190 h->current_job = NULL;
192 h->state_lock = hb_lock_init();
193 h->state.state = HB_STATE_IDLE;
195 h->pause_lock = hb_lock_init();
199 avcodec_register_all();
201 /* Start library thread */
202 hb_log( "hb_init: starting libhb thread" );
204 h->main_thread = hb_thread_init( "libhb", thread_func, h,
205 HB_NORMAL_PRIORITY );
207 hb_register( &hb_sync );
208 hb_register( &hb_decmpeg2 );
209 hb_register( &hb_decsub );
210 hb_register( &hb_render );
211 hb_register( &hb_encavcodec );
212 hb_register( &hb_encxvid );
213 hb_register( &hb_encx264 );
214 hb_register( &hb_deca52 );
215 hb_register( &hb_decdca );
216 hb_register( &hb_decavcodec );
217 hb_register( &hb_declpcm );
218 hb_register( &hb_encfaac );
219 hb_register( &hb_enclame );
220 hb_register( &hb_encvorbis );
227 * Returns current version of libhb.
228 * @param h Handle to hb_handle_t.
229 * @return character array of version number.
231 char * hb_get_version( hb_handle_t * h )
237 * Returns current build of libhb.
238 * @param h Handle to hb_handle_t.
239 * @return character array of build number.
241 int hb_get_build( hb_handle_t * h )
247 * Checks for needed update.
248 * @param h Handle to hb_handle_t.
249 * @param version Pointer to handle where version will be copied.
250 * @return update indicator.
252 int hb_check_update( hb_handle_t * h, char ** version )
254 *version = ( h->build < 0 ) ? NULL : h->version;
259 * Sets the cpu count to the desired value.
260 * @param h Handle to hb_handle_t
261 * @param cpu_count Number of CPUs to use.
263 void hb_set_cpu_count( hb_handle_t * h, int cpu_count )
265 cpu_count = MAX( 1, cpu_count );
266 cpu_count = MIN( cpu_count, 8 );
267 h->cpu_count = cpu_count;
271 * Initializes a scan of the by calling hb_scan_init
272 * @param h Handle to hb_handle_t
273 * @param path location of VIDEO_TS folder.
274 * @param title_index Desired title to scan. 0 for all titles.
276 void hb_scan( hb_handle_t * h, const char * path, int title_index )
280 /* Clean up from previous scan */
281 while( ( title = hb_list_item( h->list_title, 0 ) ) )
283 hb_list_rem( h->list_title, title );
284 hb_title_close( &title );
287 hb_log( "hb_scan: path=%s, title_index=%d", path, title_index );
288 h->scan_thread = hb_scan_init( h, path, title_index, h->list_title );
292 * Returns the list of titles found.
293 * @param h Handle to hb_handle_t
294 * @return Handle to hb_list_t of the title list.
296 hb_list_t * hb_get_titles( hb_handle_t * h )
298 return h->list_title;
302 * Create preview image of desired title a index of picture.
303 * @param h Handle to hb_handle_t.
304 * @param title Handle to hb_title_t of desired title.
305 * @param picture Index in title.
306 * @param buffer Handle to buufer were inage will be drawn.
308 void hb_get_preview( hb_handle_t * h, hb_title_t * title, int picture,
311 hb_job_t * job = title->job;
314 uint8_t * buf1, * buf2, * buf3, * buf4, * pen;
316 AVPicture pic_in, pic_preview, pic_deint, pic_crop, pic_scale;
317 struct SwsContext * context;
320 buf1 = malloc( title->width * title->height * 3 / 2 );
321 buf2 = malloc( title->width * title->height * 3 / 2 );
322 buf3 = malloc( title->width * title->height * 3 / 2 );
323 buf4 = malloc( title->width * title->height * 4 );
324 avpicture_fill( &pic_in, buf1, PIX_FMT_YUV420P,
325 title->width, title->height );
326 avpicture_fill( &pic_deint, buf2, PIX_FMT_YUV420P,
327 title->width, title->height );
328 avpicture_fill( &pic_scale, buf3, PIX_FMT_YUV420P,
329 job->width, job->height );
330 avpicture_fill( &pic_preview, buf4, PIX_FMT_RGBA32,
331 job->width, job->height );
333 // Allocate the AVPicture frames and fill in
335 memset( filename, 0, 1024 );
337 hb_get_tempory_filename( h, filename, "%x%d",
338 (intptr_t) title, picture );
340 file = fopen( filename, "r" );
343 hb_log( "hb_get_preview: fopen failed" );
347 fread( buf1, title->width * title->height * 3 / 2, 1, file );
350 if( job->deinterlace )
352 // Deinterlace and crop
353 avpicture_deinterlace( &pic_deint, &pic_in, PIX_FMT_YUV420P, title->width, title->height );
354 av_picture_crop( &pic_crop, &pic_deint, PIX_FMT_YUV420P, job->crop[0], job->crop[2] );
359 av_picture_crop( &pic_crop, &pic_in, PIX_FMT_YUV420P, job->crop[0], job->crop[2] );
362 // Get scaling context
363 context = sws_getContext(title->width - (job->crop[2] + job->crop[3]),
364 title->height - (job->crop[0] + job->crop[1]),
366 job->width, job->height, PIX_FMT_YUV420P,
367 SWS_LANCZOS, NULL, NULL, NULL);
371 pic_crop.data, pic_crop.linesize,
372 0, title->height - (job->crop[0] + job->crop[1]),
373 pic_scale.data, pic_scale.linesize);
376 sws_freeContext( context );
378 // Get preview context
379 context = sws_getContext(job->width, job->height, PIX_FMT_YUV420P,
380 job->width, job->height, PIX_FMT_RGBA32,
381 SWS_LANCZOS, NULL, NULL, NULL);
385 pic_scale.data, pic_scale.linesize,
387 pic_preview.data, pic_preview.linesize);
390 sws_freeContext( context );
392 /* Gray background */
393 p32 = (uint32_t *) buffer;
394 for( i = 0; i < ( title->width + 2 ) * ( title->height + 2 ); i++ )
399 /* Draw the picture, centered, and draw the cropping zone */
400 pen = buffer + ( title->height - job->height ) *
401 ( title->width + 2 ) * 2 + ( title->width - job->width ) * 2;
402 memset( pen, 0xFF, 4 * ( job->width + 2 ) );
403 pen += 4 * ( title->width + 2 );
404 for( i = 0; i < job->height; i++ )
407 nextLine = pen + 4 * ( title->width + 2 );
408 memset( pen, 0xFF, 4 );
410 memcpy( pen, buf4 + 4 * job->width * i, 4 * job->width );
411 pen += 4 * job->width;
412 memset( pen, 0xFF, 4 );
415 memset( pen, 0xFF, 4 * ( job->width + 2 ) );
418 avpicture_free( &pic_preview );
419 avpicture_free( &pic_scale );
420 avpicture_free( &pic_deint );
421 avpicture_free( &pic_in );
425 * Calculates job width, height, and cropping parameters.
426 * @param job Handle to hb_job_t.
427 * @param aspect Desired aspect ratio. Value of -1 uses title aspect.
428 * @param pixels Maximum desired pixel count.
430 void hb_set_size( hb_job_t * job, int aspect, int pixels )
432 hb_title_t * title = job->title;
434 int croppedWidth = title->width - title->crop[2] - title->crop[3];
435 int croppedHeight = title->height - title->crop[0] - title->crop[1];
436 int croppedAspect = title->aspect * title->height * croppedWidth /
437 croppedHeight / title->width;
443 /* Keep the best possible aspect ratio */
444 aspect = croppedAspect;
447 /* Crop if necessary to obtain the desired ratio */
448 memcpy( job->crop, title->crop, 4 * sizeof( int ) );
449 if( aspect < croppedAspect )
451 /* Need to crop on the left and right */
452 addCrop = croppedWidth - aspect * croppedHeight * title->width /
453 title->aspect / title->height;
456 addCrop = ( addCrop + 1 ) / 2;
457 job->crop[2] += addCrop;
458 job->crop[3] += addCrop;
460 else if( addCrop & 2 )
463 job->crop[2] += addCrop - 1;
464 job->crop[3] += addCrop + 1;
469 job->crop[2] += addCrop;
470 job->crop[3] += addCrop;
473 else if( aspect > croppedAspect )
475 /* Need to crop on the top and bottom */
476 addCrop = croppedHeight - croppedWidth * title->aspect *
477 title->height / aspect / title->width;
480 addCrop = ( addCrop + 1 ) / 2;
481 job->crop[0] += addCrop;
482 job->crop[1] += addCrop;
484 else if( addCrop & 2 )
487 job->crop[0] += addCrop - 1;
488 job->crop[1] += addCrop + 1;
493 job->crop[0] += addCrop;
494 job->crop[1] += addCrop;
498 /* Compute a resolution from the number of pixels and aspect */
502 h = MULTIPLE_16( w * HB_ASPECT_BASE / aspect );
510 job->height = MULTIPLE_16( 16 * i * HB_ASPECT_BASE / aspect );
514 * Returns the number of jobs in the queue.
515 * @param h Handle to hb_handle_t.
516 * @return Number of jobs.
518 int hb_count( hb_handle_t * h )
520 return hb_list_count( h->jobs );
524 * Returns handle to job at index i within the job list.
525 * @param h Handle to hb_handle_t.
526 * @param i Index of job.
527 * @returns Handle to hb_job_t of desired job.
529 hb_job_t * hb_job( hb_handle_t * h, int i )
531 return hb_list_item( h->jobs, i );
534 hb_job_t * hb_current_job( hb_handle_t * h )
536 return( h->current_job );
540 * Adds a job to the job list.
541 * @param h Handle to hb_handle_t.
542 * @param job Handle to hb_job_t.
544 void hb_add( hb_handle_t * h, hb_job_t * job )
547 hb_title_t * title, * title_copy;
548 hb_chapter_t * chapter, * chapter_copy;
549 hb_audio_t * audio, * audio_copy;
550 hb_subtitle_t * subtitle, * subtitle_copy;
556 title_copy = malloc( sizeof( hb_title_t ) );
557 memcpy( title_copy, title, sizeof( hb_title_t ) );
559 title_copy->list_chapter = hb_list_init();
560 for( i = 0; i < hb_list_count( title->list_chapter ); i++ )
562 chapter = hb_list_item( title->list_chapter, i );
563 chapter_copy = malloc( sizeof( hb_chapter_t ) );
564 memcpy( chapter_copy, chapter, sizeof( hb_chapter_t ) );
565 hb_list_add( title_copy->list_chapter, chapter_copy );
568 /* Copy the audio track(s) we want */
569 title_copy->list_audio = hb_list_init();
571 /* Do nothing about audio during first pass */
572 if( job->pass == 0 || job->pass == 2 )
574 for( i = 0; i < 8; i++ )
576 if( job->audios[i] < 0 )
580 if( ( audio = hb_list_item( title->list_audio, job->audios[i] ) ) )
582 audio_copy = malloc( sizeof( hb_audio_t ) );
583 memcpy( audio_copy, audio, sizeof( hb_audio_t ) );
584 hb_list_add( title_copy->list_audio, audio_copy );
589 title_copy->list_subtitle = hb_list_init();
592 * The following code is confusing, there are three ways in which
593 * we select subtitles and it depends on whether this is single or
596 * subtitle_scan may be enabled, in which case the first pass
597 * scans all subtitles of that language. The second pass does not
598 * select any because they are set at the end of the first pass.
600 * native_language may have a preferred language, in which case we
601 * may be switching the language we want for the subtitles in the
602 * first pass of a single pass, or the second pass of a two pass.
604 * We may have manually selected a subtitle, in which case that is
605 * selected in the first pass of a single pass, or the second of a
608 memset( audio_lang, 0, sizeof( audio_lang ) );
610 if ( job->subtitle_scan || job->native_language ) {
613 * Find the first audio language that is being encoded
615 for( i = 0; i < 8; i++ )
617 if( job->audios[i] < 0 )
621 if( ( audio = hb_list_item( title->list_audio, job->audios[i] ) ) )
623 strncpy(audio_lang, audio->iso639_2, sizeof(audio_lang));
629 * In all cases switch the language if we need to to our native
632 if( job->native_language )
634 if( strncasecmp( job->native_language, audio_lang,
635 sizeof( audio_lang ) ) != 0 )
640 hb_log( "Enabled subtitles in native language '%s', audio is in '%s'",
641 job->native_language, audio_lang);
644 * The main audio track is not in our native language, so switch
645 * the subtitles to use our native language instead.
647 strncpy( audio_lang, job->native_language, sizeof( audio_lang ) );
650 * native language is irrelevent, free it.
652 free( job->native_language );
653 job->native_language = NULL;
659 * If doing a subtitle scan then add all the matching subtitles for this
662 if ( job->subtitle_scan )
664 for( i=0; i < hb_list_count( title->list_subtitle ); i++ )
666 subtitle = hb_list_item( title->list_subtitle, i );
667 if( strcmp( subtitle->iso639_2, audio_lang ) == 0 )
670 * Matched subtitle language with audio language, so
671 * add this to our list to scan.
673 * We will update the subtitle list on the second pass
674 * later after the first pass has completed.
676 subtitle_copy = malloc( sizeof( hb_subtitle_t ) );
677 memcpy( subtitle_copy, subtitle, sizeof( hb_subtitle_t ) );
678 hb_list_add( title_copy->list_subtitle, subtitle_copy );
679 if ( job->native_language ) {
681 * With native language just select the
682 * first match in our langiage, not all of
683 * them. Subsequent ones are likely to be commentary
691 * Not doing a subtitle scan in this pass, but maybe we are in the
694 if( job->select_subtitle )
697 * Don't add subtitles here, we'll add them via select_subtitle
698 * at the end of the subtitle_scan.
702 * Definitely not doing a subtitle scan.
704 if( job->pass != 1 && job->native_language )
707 * We are not doing a subtitle scan but do want the
708 * native langauge subtitle selected, so select it
709 * for pass 0 or pass 2 of a two pass.
711 for( i=0; i < hb_list_count( title->list_subtitle ); i++ )
713 subtitle = hb_list_item( title->list_subtitle, i );
714 if( strcmp( subtitle->iso639_2, audio_lang ) == 0 )
717 * Matched subtitle language with audio language, so
718 * add this to our list to scan.
720 subtitle_copy = malloc( sizeof( hb_subtitle_t ) );
721 memcpy( subtitle_copy, subtitle, sizeof( hb_subtitle_t ) );
722 hb_list_add( title_copy->list_subtitle, subtitle_copy );
728 * Manually selected subtitle, in which case only
729 * bother adding them for pass 0 or pass 2 of a two
734 if( ( subtitle = hb_list_item( title->list_subtitle, job->subtitle ) ) )
736 subtitle_copy = malloc( sizeof( hb_subtitle_t ) );
737 memcpy( subtitle_copy, subtitle, sizeof( hb_subtitle_t ) );
738 hb_list_add( title_copy->list_subtitle, subtitle_copy );
746 job_copy = calloc( sizeof( hb_job_t ), 1 );
747 memcpy( job_copy, job, sizeof( hb_job_t ) );
748 title_copy->job = job_copy;
749 job_copy->title = title_copy;
750 job_copy->file = strdup( job->file );
752 job_copy->pause = h->pause_lock;
754 /* Copy the job filter list */
758 int filter_count = hb_list_count( job->filters );
759 job_copy->filters = hb_list_init();
760 for( i = 0; i < filter_count; i++ )
762 hb_filter_object_t * filter = hb_list_item( job->filters, i );
763 hb_list_add( job_copy->filters, filter );
767 /* Add the job to the list */
768 hb_list_add( h->jobs, job_copy );
769 h->job_count = hb_count(h);
770 h->job_count_permanent++;
774 * Removes a job from the job list.
775 * @param h Handle to hb_handle_t.
776 * @param job Handle to hb_job_t.
778 void hb_rem( hb_handle_t * h, hb_job_t * job )
780 hb_list_rem( h->jobs, job );
782 h->job_count = hb_count(h);
783 if (h->job_count_permanent)
784 h->job_count_permanent--;
786 /* XXX free everything XXX */
790 * Starts the conversion process.
791 * Sets state to HB_STATE_WORKING.
792 * calls hb_work_init, to launch work thread. Stores handle to work thread.
793 * @param h Handle to hb_handle_t.
795 void hb_start( hb_handle_t * h )
798 h->job_count = hb_list_count( h->jobs );
800 hb_lock( h->state_lock );
801 h->state.state = HB_STATE_WORKING;
802 #define p h->state.param.working
805 p.job_count = h->job_count;
812 hb_unlock( h->state_lock );
817 h->work_thread = hb_work_init( h->jobs, h->cpu_count,
818 &h->work_die, &h->work_error, &h->current_job );
822 * Pauses the conversion process.
823 * @param h Handle to hb_handle_t.
825 void hb_pause( hb_handle_t * h )
829 hb_lock( h->pause_lock );
832 hb_lock( h->state_lock );
833 h->state.state = HB_STATE_PAUSED;
834 hb_unlock( h->state_lock );
839 * Resumes the conversion process.
840 * @param h Handle to hb_handle_t.
842 void hb_resume( hb_handle_t * h )
846 hb_unlock( h->pause_lock );
852 * Stops the conversion process.
853 * @param h Handle to hb_handle_t.
855 void hb_stop( hb_handle_t * h )
859 h->job_count = hb_count(h);
860 h->job_count_permanent = 0;
866 * Returns the state of the conversion process.
867 * @param h Handle to hb_handle_t.
868 * @param s Handle to hb_state_t which to copy the state data.
870 void hb_get_state( hb_handle_t * h, hb_state_t * s )
872 hb_lock( h->state_lock );
874 memcpy( s, &h->state, sizeof( hb_state_t ) );
875 if ( h->state.state == HB_STATE_SCANDONE || h->state.state == HB_STATE_WORKDONE )
876 h->state.state = HB_STATE_IDLE;
878 hb_unlock( h->state_lock );
881 void hb_get_state2( hb_handle_t * h, hb_state_t * s )
883 hb_lock( h->state_lock );
885 memcpy( s, &h->state, sizeof( hb_state_t ) );
887 hb_unlock( h->state_lock );
891 * Called in MacGui in UpdateUI to check
892 * for a new scan being completed to set a new source
894 int hb_get_scancount( hb_handle_t * h)
900 * Closes access to libhb by freeing the hb_handle_t handle ontained in hb_init_real.
901 * @param _h Pointer to handle to hb_handle_t.
903 void hb_close( hb_handle_t ** _h )
905 hb_handle_t * h = *_h;
909 hb_thread_close( &h->main_thread );
911 while( ( title = hb_list_item( h->list_title, 0 ) ) )
913 hb_list_rem( h->list_title, title );
914 if( title->job && title->job->filters )
916 hb_list_close( &title->job->filters );
919 hb_title_close( &title );
921 hb_list_close( &h->list_title );
923 hb_list_close( &h->jobs );
924 hb_lock_close( &h->state_lock );
925 hb_lock_close( &h->pause_lock );
931 * Monitors the state of the update, scan, and work threads.
932 * Sets scan done state when scan thread exits.
933 * Sets work done state when work thread exits.
934 * @param _h Handle to hb_handle_t
936 static void thread_func( void * _h )
938 hb_handle_t * h = (hb_handle_t *) _h;
941 struct dirent * entry;
945 /* Create folder for temporary files */
946 memset( dirname, 0, 1024 );
947 hb_get_tempory_directory( h, dirname );
953 /* In case the check_update thread hangs, it'll die sooner or
954 later. Then, we join it here */
955 if( h->update_thread &&
956 hb_thread_has_exited( h->update_thread ) )
958 hb_thread_close( &h->update_thread );
961 /* Check if the scan thread is done */
962 if( h->scan_thread &&
963 hb_thread_has_exited( h->scan_thread ) )
965 hb_thread_close( &h->scan_thread );
967 hb_log( "libhb: scan thread found %d valid title(s)",
968 hb_list_count( h->list_title ) );
969 hb_lock( h->state_lock );
970 h->state.state = HB_STATE_SCANDONE; //originally state.state
971 hb_unlock( h->state_lock );
972 /*we increment this sessions scan count by one for the MacGui
973 to trigger a new source being set */
977 /* Check if the work thread is done */
978 if( h->work_thread &&
979 hb_thread_has_exited( h->work_thread ) )
981 hb_thread_close( &h->work_thread );
983 hb_log( "libhb: work result = %d",
985 hb_lock( h->state_lock );
986 h->state.state = HB_STATE_WORKDONE;
987 h->state.param.workdone.error = h->work_error;
989 h->job_count = hb_count(h);
990 if (h->job_count < 1)
991 h->job_count_permanent = 0;
992 hb_unlock( h->state_lock );
1001 hb_thread_close( &h->work_thread );
1004 /* Remove temp folder */
1005 dir = opendir( dirname );
1006 while( ( entry = readdir( dir ) ) )
1008 char filename[1024];
1009 if( entry->d_name[0] == '.' )
1013 memset( filename, 0, 1024 );
1014 snprintf( filename, 1023, "%s/%s", dirname, entry->d_name );
1023 * @param h Handle to hb_handle_t
1025 int hb_get_pid( hb_handle_t * h )
1031 * Sets the current state.
1032 * @param h Handle to hb_handle_t
1033 * @param s Handle to new hb_state_t
1035 void hb_set_state( hb_handle_t * h, hb_state_t * s )
1037 hb_lock( h->pause_lock );
1038 hb_lock( h->state_lock );
1039 memcpy( &h->state, s, sizeof( hb_state_t ) );
1040 if( h->state.state == HB_STATE_WORKING )
1043 if (h->job_count < 1)
1044 h->job_count_permanent = 1;
1046 h->state.param.working.job_cur =
1047 h->job_count_permanent - hb_list_count( h->jobs );
1048 h->state.param.working.job_count = h->job_count_permanent;
1050 hb_unlock( h->state_lock );
1051 hb_unlock( h->pause_lock );