JNIEXPORT jint Java_com_dropcam_android_media_H264Decoder_consumeNalUnitsFromDirectBuffer(JNIEnv* env, jobject thiz, jobject nal_units, jint num_bytes, jlong pkt_pts) { DecoderContext *ctx = get_ctx(env, thiz); void *buf = NULL; if (nal_units == NULL) { D("Received null buffer, sending empty packet to decoder"); } else { buf = (*env)->GetDirectBufferAddress(env, nal_units); if (buf == NULL) { D("Error getting direct buffer address"); return -1; } } AVPacket packet = { .data = (uint8_t*)buf, .size = num_bytes, .pts = pkt_pts }; int frameFinished = 0; int res = avcodec_decode_video2(ctx->codec_ctx, ctx->src_frame, &frameFinished, &packet); if (frameFinished) ctx->frame_ready = 1; return res; } JNIEXPORT jboolean Java_com_dropcam_android_media_H264Decoder_isFrameReady(JNIEnv* env, jobject thiz) { DecoderContext *ctx = get_ctx(env, thiz); return ctx->frame_ready ? JNI_TRUE : JNI_FALSE; }
BOOL io_grow(io_struct *ps, uint32 extra_space) { uint32 new_size; char *new_data; ps->grow_size = MAX(ps->grow_size, ps->data_offset + extra_space); if(ps->data_offset + extra_space <= ps->buffer_size) return True; /* * We cannot grow the buffer if we're not reading * into the io_struct, or if we don't own the memory. */ if(UNMARSHALLING(ps) || !ps->is_dynamic) { DEBUG(0,("io_grow: Buffer overflow - unable to expand buffer by %u bytes.\n", (unsigned int)extra_space)); return False; } /* * Decide how much extra space we really need. */ extra_space -= (ps->buffer_size - ps->data_offset); if(ps->buffer_size == 0) { /* * Ensure we have at least a PDU's length, or extra_space, whichever * is greater. */ new_size = MAX(IO_MAX_INITIAL_SPACE, extra_space); if((new_data = talloc(get_ctx(ps), new_size)) == NULL) { DEBUG(0,("io_grow: Malloc failure for size %u.\n", (unsigned int)new_size)); return False; } memset(new_data, '\0', new_size ); } else { /* * If the current buffer size is bigger than the space needed, just * double it, else add extra_space. */ new_size = MAX(ps->buffer_size*2, ps->buffer_size + extra_space); if ((new_data = trealloc(get_ctx(ps), ps->data_p, new_size)) == NULL) { DEBUG(0,("io_grow: Realloc failure for size %u.\n", (unsigned int)new_size)); return False; } } ps->buffer_size = new_size; ps->data_p = new_data; return True; }
BOOL io_init(io_struct *ps, uint32 size, BOOL io) { io_free(ps); ps->io = io; ps->bigendian_data = False; ps->is_dynamic = False; ps->data_offset = 0; ps->buffer_size = 0; ps->data_p = NULL; ps->format_string = NULL; ps->format_offset = 0; ps->entry_count = NULL; ps->receive_buf = NULL; ps->receive_len = NULL; ps->ctx = NULL; if (size != 0) { ps->buffer_size = size; if((ps->data_p = (char *)talloc(get_ctx(ps), (size_t)size)) == NULL) { DEBUG(0,("io_init: malloc fail for %u bytes.\n", (unsigned int)size)); return False; } ps->is_dynamic = True; /* We own this memory. */ } return True; }
static void handle_fault(L4_Word_t faddr, L4_Word_t fip, L4_MapItem_t *map) { struct drop_param *param = get_ctx(); L4_MsgTag_t tag = muidl_get_tag(); int rwx = tag.X.label & 0x000f; #if 0 L4_ThreadId_t from = muidl_get_sender(); diag("drop_pager: pf in %lu:%lu at %#lx, ip %#lx", L4_ThreadNo(from), L4_Version(from), faddr, fip); #endif param->log_top = (param->log_top + 1) % LOG_SIZE; param->log[param->log_top] = L4_FpageLog2(faddr, 12); L4_Set_Rights(¶m->log[param->log_top], rwx); int dpos = param->log_top - param->keep; if(dpos < 0) dpos += LOG_SIZE; assert(dpos >= 0 && dpos < LOG_SIZE); L4_Fpage_t drop = param->log[dpos]; if(!L4_IsNilFpage(drop) && L4_Address(drop) != (faddr & ~PAGE_MASK)) { #if 0 diag("flushing %#lx:%#lx (dpos %d)", L4_Address(drop), L4_Size(drop), dpos); #endif L4_Set_Rights(&drop, L4_FullyAccessible); L4_FlushFpage(drop); } /* pass it on. */ L4_LoadBR(0, L4_CompleteAddressSpace.raw); L4_LoadMR(0, (L4_MsgTag_t){ .X.label = 0xffe0 | rwx, .X.u = 2 }.raw);
Settings_screen::Settings_screen(Game_object::World_objects &objs, Core::World &world, Core::Context &ctx) : State(objs, world, ctx) , m_camera(get_world().find_entity_by_name("Main Camera")) , m_controllers{ Core::Controller(get_ctx(), 0), Core::Controller(get_ctx(), 1), Core::Controller(get_ctx(), 2), Core::Controller(get_ctx(), 3), } { // We use mouse for screen menu. Core::Input::mouse_set_capture(get_ctx(), false); assert(m_camera); Game_object::Main_camera *main_camera = reinterpret_cast<Game_object::Main_camera*>(m_camera.get_user_data()); assert(main_camera); // Buttons { m_buttons[0].entity = Core::Entity(world); m_buttons[0].entity.set_name("button_title"); m_buttons[0].entity.set_tags(Object_tags::gui_cam); m_buttons[0].cold_material = Factory::Material::get_settings_menu_title(); m_buttons[0].hot_material = Core::Material(); m_buttons[1].entity = Core::Entity(world); m_buttons[1].entity.set_name("button_fullscreen"); m_buttons[1].entity.set_tags(Object_tags::gui_cam); m_buttons[1].cold_material = Factory::Material::get_settings_menu_fullscreen_cold(); m_buttons[1].hot_material = Factory::Material::get_settings_menu_fullscreen_hot(); m_buttons[2].entity = Core::Entity(world); m_buttons[2].entity.set_name("button_back"); m_buttons[2].entity.set_tags(Object_tags::gui_cam); m_buttons[2].cold_material = Factory::Material::get_menu_back_cold(); m_buttons[2].hot_material = Factory::Material::get_menu_back_hot(); const Core::Model model(Core::Directory::volatile_resource_path("assets/models/unit_cube.obj")); Core::Lib::Menu_list::inititalize(m_buttons, Settings_screen_utils::get_button_count(), model, main_camera->m_gui_camera); } }
int zmq::socket_base_t::close () { shutting_down = true; // Let the thread know that the socket is no longer available. app_thread->remove_socket (this); // Pointer to the context must be retrieved before the socket is // deallocated. Afterwards it is not available. ctx_t *ctx = get_ctx (); // Unregister all inproc endpoints associated with this socket. // From this point we are sure that inc_seqnum won't be called again // on this object. ctx->unregister_endpoints (this); // Wait till all undelivered commands are delivered. This should happen // very quickly. There's no way to wait here for extensive period of time. while (processed_seqnum != sent_seqnum.get ()) app_thread->process_commands (true, false); while (true) { // On third pass of the loop there should be no more I/O objects // because all connecters and listerners were destroyed during // the first pass and all engines delivered by delayed 'own' commands // are destroyed during the second pass. if (io_objects.empty () && !pending_term_acks) break; // Send termination request to all associated I/O objects. for (io_objects_t::iterator it = io_objects.begin (); it != io_objects.end (); it++) send_term (*it); // Move the objects to the list of pending term acks. pending_term_acks += io_objects.size (); io_objects.clear (); // Process commands till we get all the termination acknowledgements. while (pending_term_acks) app_thread->process_commands (true, false); } // Check whether there are no session leaks. sessions_sync.lock (); zmq_assert (named_sessions.empty ()); zmq_assert (unnamed_sessions.empty ()); sessions_sync.unlock (); delete this; // This function must be called after the socket is completely deallocated // as it may cause termination of the whole 0MQ infrastructure. ctx->destroy_socket (); return 0; }
static int engine_ctrl(ENGINE *engine, int cmd, long i, void *p, void (*f) ()) { ENGINE_CTX *ctx; ctx = get_ctx(engine); if (ctx == NULL) return 0; return pkcs11_engine_ctrl(ctx, cmd, i, p, f); }
/* Finish engine operations initialized with pkcs11_init() */ static int engine_finish(ENGINE *engine) { ENGINE_CTX *ctx; ctx = get_ctx(engine); if (ctx == NULL) return 0; return pkcs11_finish(ctx); }
/* * Force a screen update. */ void term_update(void) { Context ctx; ctx = get_ctx(); if (ctx) { do_paint (ctx, TRUE); free_ctx (ctx); nl_count = 0; scroll_heuristic = 0; } }
static EVP_PKEY *load_privkey(ENGINE *engine, const char *s_key_id, UI_METHOD *ui_method, void *callback_data) { ENGINE_CTX *ctx; ctx = get_ctx(engine); if (ctx == NULL) return 0; return pkcs11_load_private_key(ctx, s_key_id, ui_method, callback_data); }
/*! Assert that \p sub lies in context \p ctx. * \return related pattern */ template<class... Tp> inline Ctx* ctx(PCTX_t ctx, Base* sub) { auto ctxS = dynamic_cast<Ctx*>(sub); if (ctxS and ctxS->get_ctx() == ctx) { // \c this and its \c sub are same context return ctxS; } else { return new Ctx(ctx, sub); } }
/* Destroy the context allocated with pkcs11_new() */ static int engine_destroy(ENGINE *engine) { ENGINE_CTX *ctx; int rv; ctx = get_ctx(engine); if (ctx == NULL) return 0; rv = pkcs11_destroy(ctx); ENGINE_set_ex_data(engine, pkcs11_idx, NULL); return rv; }
JNIEXPORT void Java_org_opencv_samples_tutorial2_H264Decoder_nativeDestroy(JNIEnv* env, jobject thiz) { DecoderContext *ctx = get_ctx(env, thiz); D("Destroying native H264 decoder context"); avcodec_close(ctx->codec_ctx); av_free(ctx->codec_ctx); av_free(ctx->src_frame); av_free(ctx->dst_frame); free(ctx); }
JNIEXPORT void Java_com_dropcam_android_media_H264Decoder_nativeDestroy(JNIEnv* env, jobject thiz) { DecoderContext *ctx = get_ctx(env, thiz); D("Destroying native H264 decoder context"); avcodec_close(ctx->codec_ctx); av_free(ctx->codec_ctx); av_free(ctx->src_frame); av_free(ctx->dst_frame); free(ctx); }
int zmq::socket_base_t::monitor (const char *addr_, int events_) { int rc; if (unlikely (ctx_terminated)) { errno = ETERM; return -1; } // Support deregistering monitoring endpoints as well if (addr_ == NULL) { stop_monitor (); return 0; } // Parse addr_ string. std::string protocol; std::string address; rc = parse_uri (addr_, protocol, address); if (rc != 0) return -1; rc = check_protocol (protocol); if (rc != 0) return -1; // Event notification only supported over inproc:// if (protocol != "inproc") { errno = EPROTONOSUPPORT; return -1; } // Register events to monitor monitor_events = events_; monitor_socket = zmq_socket (get_ctx (), ZMQ_PAIR); if (monitor_socket == NULL) return -1; // Never block context termination on pending event messages int linger = 0; rc = zmq_setsockopt (monitor_socket, ZMQ_LINGER, &linger, sizeof (linger)); if (rc == -1) stop_monitor (); // Spawn the monitor socket endpoint rc = zmq_bind (monitor_socket, addr_); if (rc == -1) stop_monitor (); return rc; }
static void get_fault_log(L4_Fpage_t *faults_buf, unsigned *faults_len_p) { struct drop_param *ctx = get_ctx(); int o = 0; for(int i = 0, p = ctx->log_top; i < LOG_SIZE; i++, p = (p + 1) % LOG_SIZE) { assert(p > 0 && p < LOG_SIZE); assert(o < LOG_SIZE); if(!L4_IsNilFpage(ctx->log[p])) { faults_buf[o++] = ctx->log[p]; } } *faults_len_p = o; }
JNIEXPORT jlong Java_org_opencv_samples_tutorial2_H264Decoder_decodeFrameToDirectBuffer(JNIEnv* env, jobject thiz, jobject out_buffer) { DecoderContext *ctx = get_ctx(env, thiz); if (!ctx->frame_ready) return -1; void *out_buf = (*env)->GetDirectBufferAddress(env, out_buffer); if (out_buf == NULL) { D("Error getting direct buffer address"); return -1; } long out_buf_len = (*env)->GetDirectBufferCapacity(env, out_buffer); int pic_buf_size = avpicture_get_size(ctx->color_format, ctx->codec_ctx->width, ctx->codec_ctx->height); if (out_buf_len < pic_buf_size) { D("Input buffer too small,pic_buf_size = %d",pic_buf_size); return -1; } if (ctx->color_format == COLOR_FORMAT_YUV420) { D("format = COLOR_FORMAT_YUV420,out_buf_len = %d,pic_buf_size = %d",out_buf_len , pic_buf_size); memcpy(ctx->src_frame->data, out_buffer, pic_buf_size); } else { if (ctx->convert_ctx == NULL) { ctx->convert_ctx = sws_getContext(ctx->codec_ctx->width, ctx->codec_ctx->height, ctx->codec_ctx->pix_fmt, ctx->codec_ctx->width, ctx->codec_ctx->height, ctx->color_format, SWS_FAST_BILINEAR, NULL, NULL, NULL); } avpicture_fill((AVPicture*)ctx->dst_frame, (uint8_t*)out_buf, ctx->color_format, ctx->codec_ctx->width, ctx->codec_ctx->height); sws_scale(ctx->convert_ctx, (const uint8_t**)ctx->src_frame->data, ctx->src_frame->linesize, 0, ctx->codec_ctx->height, ctx->dst_frame->data, ctx->dst_frame->linesize); } ctx->frame_ready = 0; if (ctx->src_frame->pkt_pts == AV_NOPTS_VALUE) { D("No PTS was passed from avcodec_decode!"); } return ctx->src_frame->pkt_pts; }
JNIEXPORT jint Java_org_opencv_samples_tutorial2_H264Decoder_getOutputByteSize(JNIEnv* env, jobject thiz) { DecoderContext *ctx = get_ctx(env, thiz); return avpicture_get_size(ctx->color_format, ctx->codec_ctx->width, ctx->codec_ctx->height); }
std::unique_ptr<State> Settings_screen::on_update() { Game_object::Main_camera *main_camera = reinterpret_cast<Game_object::Main_camera*>(m_camera.get_user_data()); assert(main_camera); Core::Lib::Menu_list::navigate(m_controllers[0], m_buttons, Settings_screen_utils::get_button_count()); Core::Lib::Menu_list::mouse_over(main_camera->m_gui_camera, get_world(), Core::Input::mouse_get_coordinates(get_ctx()), m_buttons, Settings_screen_utils::get_button_count()); const Core::Entity_ref selected_button = m_buttons[0].entity; constexpr uint32_t button_start = Core::Gamepad_button::a | Core::Gamepad_button::start; if(selected_button && strcmp(selected_button.get_name(), "button_back") == 0) { if(m_controllers[0].is_button_up_on_frame(button_start)) { Core::Lib::Menu_list::clear(m_buttons, Settings_screen_utils::get_button_count()); return std::unique_ptr<State>(new Game::Title_screen(get_world_objs(), get_world(), get_ctx())); } } else if(selected_button && strcmp(selected_button.get_name(), "button_fullscreen") == 0) { if(m_controllers[0].is_button_up_on_frame(button_start)) { get_ctx().set_fullscreen(!get_ctx().is_fullscreen()); if(!get_ctx().is_fullscreen()) { get_ctx().set_resolution(1024, 576); get_ctx().set_title("Vertex Defender"); } // Get cameras if(main_camera) { main_camera->m_world_camera.set_height(get_ctx().get_height()); main_camera->m_world_camera.set_width(get_ctx().get_width()); main_camera->m_gui_camera.set_height(get_ctx().get_height()); main_camera->m_gui_camera.set_width(get_ctx().get_width()); main_camera->m_final_post_camera.set_width(get_ctx().get_width()); main_camera->m_final_post_camera.set_height(get_ctx().get_height()); main_camera->m_level_camera.set_width(get_ctx().get_width()); main_camera->m_level_camera.set_height(get_ctx().get_height()); Core::Lib::Menu_list::clear(m_buttons, Settings_screen_utils::get_button_count()); return std::unique_ptr<State>(new Game::Settings_screen(get_world_objs(), get_world(), get_ctx())); } } } // Generic if back then go back if(m_controllers[0].is_button_up_on_frame(Core::Gamepad_button::back)) { Core::Lib::Menu_list::clear(m_buttons, Settings_screen_utils::get_button_count()); return std::unique_ptr<State>(new Game::Title_screen(get_world_objs(), get_world(), get_ctx())); } return nullptr; }
JNIEXPORT jint Java_com_dropcam_android_media_H264Decoder_getHeight(JNIEnv* env, jobject thiz) { DecoderContext *ctx = get_ctx(env, thiz); return ctx->codec_ctx->height; }
static void set_params(int32_t n_keep) { struct drop_param *p = get_ctx(); p->keep = n_keep; }
void zmq::socket_base_t::va_monitor_event (int event_, va_list args) { get_ctx ()->va_monitor_event (this, event_, args); }
/******************************************************************* format string ********************************************************************/ BOOL io_parse_format(io_struct *ps, int num_items, const char *type, unsigned flags) { char fmt; uint32 offs; size_t fmt_size; BOOL fmt_string = False; if (num_items < 1 || num_items > 99) return False; if (strequal(type,"uint8") || strequal(type,"uint8s")) { fmt = 'B'; fmt_size = 1; } else if (strequal(type,"uint16")) { fmt = 'W'; fmt_size = 2; } else if (strequal(type,"uint32")) { fmt = 'D'; fmt_size = 4; } else if (strequal(type,"SMBCHR")) { fmt = 'z'; if (num_items != 1) return False; fmt_size = 1; fmt_string = True; } else return False; if (!(flags & PARSE_SCALARS)) return True; if (UNMARSHALLING(ps)) { size_t item_size = 0; int nitems = 0; BOOL is_string = False; if (!io_format_interp(ps, &item_size, &nitems, &is_string)) return False; return (is_string == fmt_string && nitems == num_items && item_size == fmt_size); } offs = ps->format_offset; ps->format_offset++; if (num_items > 1) ps->format_offset++; if (num_items >= 10) ps->format_offset++; ps->format_string = trealloc(get_ctx(ps), ps->format_string, ps->format_offset+1); if (ps->format_string == NULL) return False; if (num_items == 1) slprintf(&ps->format_string[offs], 1+ps->format_offset-offs, "%c", fmt); else slprintf(&ps->format_string[offs], 1+ps->format_offset-offs, "%c%d", fmt, num_items); DEBUG(10,("format_string: %s\n", ps->format_string)); return True; }
JNIEXPORT jint Java_org_opencv_samples_tutorial2_H264Decoder_getHeight(JNIEnv* env, jobject thiz) { DecoderContext *ctx = get_ctx(env, thiz); return ctx->codec_ctx->height; }
JNIEXPORT jint Java_com_dropcam_android_media_H264Decoder_getOutputByteSize(JNIEnv* env, jobject thiz) { DecoderContext *ctx = get_ctx(env, thiz); return avpicture_get_size(ctx->color_format, ctx->codec_ctx->width, ctx->codec_ctx->height); }
CMatGsuBoard::CMatGsuBoard() : CMatBase(s_grid_size, s_grid_size) { auto ctx = get_ctx(); // grids ctx->set_source(SolidPattern::create_rgba(0, 0, 0, 0.01)); for (int i = 0; i < s_grid_size; ++i) { for (int j = 0; j < s_grid_size; ++j) { ctx->move_to(i, 1); ctx->line_to(i, s_grid_size-1); ctx->move_to(1, j); ctx->line_to(s_grid_size-1, j); ctx->stroke(); } } ctx->save(); ctx->translate(s_grid_size/2, s_grid_size/2); // 1. background color auto pat = gw_create_solidpat({0, 0, 0}); ctx->set_source(pat); // center rectangle ctx->rectangle(-2,-2, 4,4); ctx->rectangle(-3, -3, 6, 6); ctx->stroke(); // v line ctx->move_to(0, -6); ctx->line_to(0, 9); ctx->stroke(); // h line ctx->move_to(-9, 0); ctx->line_to(9, 0); ctx->stroke(); // player home for (int i = 0; i < 3; ++i) { ctx->save(); ctx->rotate(M_PI * 0.5 * i); for (int i = 4; i < 7; ++i) { ctx->move_to(i, -1); ctx->line_to(i, 1); } ctx->rectangle(7, -1, 2, 2); ctx->move_to(8, -1); ctx->line_to(8, 1); ctx->stroke(); ctx->restore(); } // award for (int i = 4; i < 7; ++i) { ctx->move_to(-1, -i); ctx->line_to(1, -i); } ctx->stroke(); ctx->restore(); // cross points ctx->set_source(SolidPattern::create_rgba(0, 1, 1, 0.2)); for (int y = 0; y <= s_grid_size; ++y) { for (int x = 0; x <= s_grid_size; ++x) { if (points[y][x] == 1) { ctx->arc(x, y, 0.5, 0, M_PI * 2); ctx->fill(); } } } return; }