Home | History | Annotate | Download | only in xcore
      1 /*
      2  * image_processor.h - 3a image processor
      3  *
      4  *  Copyright (c) 2014-2015 Intel Corporation
      5  *
      6  * Licensed under the Apache License, Version 2.0 (the "License");
      7  * you may not use this file except in compliance with the License.
      8  * You may obtain a copy of the License at
      9  *
     10  *      http://www.apache.org/licenses/LICENSE-2.0
     11  *
     12  * Unless required by applicable law or agreed to in writing, software
     13  * distributed under the License is distributed on an "AS IS" BASIS,
     14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15  * See the License for the specific language governing permissions and
     16  * limitations under the License.
     17  *
     18  * Author: Wind Yuan <feng.yuan (at) intel.com>
     19  */
     20 
     21 #ifndef XCAM_IMAGE_PROCESSOR_H
     22 #define XCAM_IMAGE_PROCESSOR_H
     23 
     24 #include <xcam_std.h>
     25 #include <video_buffer.h>
     26 #include <x3a_result.h>
     27 #include <safe_list.h>
     28 
     29 namespace XCam {
     30 
     31 class ImageProcessor;
     32 
     33 /* callback interface */
     34 class ImageProcessCallback {
     35 public:
     36     ImageProcessCallback () {}
     37     virtual ~ImageProcessCallback () {}
     38     virtual void process_buffer_done (ImageProcessor *processor, const SmartPtr<VideoBuffer> &buf);
     39     virtual void process_buffer_failed (ImageProcessor *processor, const SmartPtr<VideoBuffer> &buf);
     40     virtual void process_image_result_done (ImageProcessor *processor, const SmartPtr<X3aResult> &result);
     41 
     42 private:
     43     XCAM_DEAD_COPY (ImageProcessCallback);
     44 };
     45 
     46 class ImageProcessorThread;
     47 class X3aResultsProcessThread;
     48 
     49 /* base class, ImageProcessor */
     50 class ImageProcessor
     51 {
     52     friend class ImageProcessorThread;
     53     friend class X3aResultsProcessThread;
     54 
     55     typedef SafeList<VideoBuffer> VideoBufQueue;
     56 
     57 public:
     58     explicit ImageProcessor (const char* name);
     59     virtual ~ImageProcessor ();
     60 
     61     const char *get_name () const {
     62         return _name;
     63     }
     64 
     65     bool set_callback (ImageProcessCallback *callback);
     66     XCamReturn start();
     67     XCamReturn stop ();
     68 
     69     XCamReturn push_buffer (SmartPtr<VideoBuffer> &buf);
     70     XCamReturn push_3a_results (X3aResultList &results);
     71     XCamReturn push_3a_result (SmartPtr<X3aResult> &result);
     72 
     73 protected:
     74     virtual bool can_process_result (SmartPtr<X3aResult> &result) = 0;
     75     virtual XCamReturn apply_3a_results (X3aResultList &results) = 0;
     76     virtual XCamReturn apply_3a_result (SmartPtr<X3aResult> &result) = 0;
     77     // buffer runs in another thread
     78     virtual XCamReturn process_buffer(SmartPtr<VideoBuffer> &input, SmartPtr<VideoBuffer> &output) = 0;
     79     virtual XCamReturn emit_start ();
     80     virtual void emit_stop ();
     81 
     82 
     83     void notify_process_buffer_done (const SmartPtr<VideoBuffer> &buf);
     84     void notify_process_buffer_failed (const SmartPtr<VideoBuffer> &buf);
     85 
     86 private:
     87     void filter_valid_results (X3aResultList &input, X3aResultList &valid_results);
     88     XCamReturn buffer_process_loop ();
     89 
     90     XCamReturn process_3a_results (X3aResultList &results);
     91     XCamReturn process_3a_result (SmartPtr<X3aResult> &result);
     92 
     93 private:
     94     XCAM_DEAD_COPY (ImageProcessor);
     95 
     96 protected:
     97     char                               *_name;
     98     ImageProcessCallback               *_callback;
     99     SmartPtr<ImageProcessorThread>      _processor_thread;
    100     VideoBufQueue                       _video_buf_queue;
    101     SmartPtr<X3aResultsProcessThread>   _results_thread;
    102 };
    103 
    104 };
    105 
    106 #endif //XCAM_IMAGE_PROCESSOR_H
    107